+ 15
In java, why we have to save a file name of java program is also must be same as the program's first class name...
why it is same as the file name and the class name???
4 Answers
+ 12
thanks for clear the doubt...
+ 5
its is convension..not a rule
you can change the file name of java..
but the problem we face that is..
the ".Class"
of any file in java is same as the class name..
like an eq
class A
{
public static void main(String... a)
{
int a[]={1,2,3};
System.out.print (a[2]);
}
}
i save this file with the name of
"cat.java"
now what happened --->>>
when you compile this code
you do this way
"javac cat.java"
when go back and see the name of ".Class file name"
--->>A.Class
so java made the convension the name of class is the name of java file..
if you not do this.
you have to remember two name instead of one class name
it work like this.
javac cat.java
java A
complile time -->>file name
run time--->>.class name
+ 5
welcome