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.
4 Antworten
+ 3
U can blindly say true when just asked abt if they shld have same names :)
+ 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.
+ 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
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?