IS it Compulsory that a class name is same as file name in java?
Answers were Sorted based on User's Feedback
Answer / anuj sharma
No its not compulsory.
when you will compile the program then u will have the need
of java file that would be the naem of your .java file but
when u will run then after compilation .class will be
generate with same naem whatever you gave the class name in
java program. So no need to give the same name always.
its upto you coz its just a good practice purpose that we
usually give the same name of java file as our class name
with Iitial charater as Capital.
Is This Answer Correct ? | 5 Yes | 0 No |
Answer / rasmitha
No.
Example:
class Test
{
Public static void main(String args[])
{
----------------
----------------------
}
Save the progrm as Ex1.java(any name we can give)
when we compile
>>javac Ex1.java
when we run the program to use class name having main method
>>java Test (it is must because execution starts with main)
Is This Answer Correct ? | 4 Yes | 0 No |
Answer / linju
yes thhe main class name must be same as the class name in
java......
Is This Answer Correct ? | 4 Yes | 4 No |
Answer / mohit jain
No its not compulsory for all program but some program are needed to same...
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / ajay gunjal
It is only recommended to use class name as a file name but it is not compulsory.
but if you have two or more classes with one is public and in that you write main() function then compiler create all class file but for searching of the entry point it is difficult and very tedious job.
so that's why if the class is public then use class name as a file name.
Is This Answer Correct ? | 0 Yes | 0 No |
How to maintain session in Jsp?
doors.txt;10;15
How to add flash or *.gif file in edit panel in java?
<% for(inti=0;i>3;++i;) sop(i); %> %
give me the small script to add a global page through any domain?
IS it Compulsory that a class name is same as file name in java?
7 Answers Sun Microsystems, Wipro,