0

Java file must have the same name as its class?

Is it realy true? Bcause in challenge questions its answer is true. I have used different name of java file and it compiles fine.

19th Apr 2017, 6:09 AM
Pintu
Pintu - avatar
4 odpowiedzi
+ 3
U can blindly say true when just asked abt if they shld have same names :)
19th Apr 2017, 1:24 PM
Manideep
Manideep - avatar
+ 2
Its is true that Java files should have same name as class name.But that restriction only applies to java codes which have public classes . example: public class program { In this case ur file name should be same as class name that is program.or else it will show compiler error. where as when u have declared like this class program { without declaring it as public u can name ur java file with any name.
19th Apr 2017, 7:58 AM
Manideep
Manideep - avatar
+ 2
It depends on you because we can use different name to save file but many time after code is compiled then we have to add the class name to run program but many of us makes mistakes here they give file name here & then program will not run. That's why we give file name and class name same
19th Apr 2017, 12:21 PM
Aniket Dhanak
Aniket Dhanak - avatar
0
If it depends on class type then how it can be true? what should we choose if we have only true or false as its options?
19th Apr 2017, 1:21 PM
Pintu
Pintu - avatar