0
java file must have the same name as java file?? true or false?? this is the question and answer in sololearn is true......
but is it necessary u can save .java file with any name and compile in commandline successfully using javac compiler...then u can execute it using class name in which main method is present......so it is not must to have java file name as class file name
22 Answers
+ 3
hope this is better explanation
https://code.sololearn.com/ch3CMVGBoJvd/?ref=app
+ 3
thanks martin u cleared one of my mistake now i know if use public class than i must have to save java file name as class name
+ 2
in question i am talking about .java file not about .class file read it...
+ 2
ok sorry but ur question was not clear plz can u clearly ask ur question i'll try to answer it if know.
+ 2
yeah it is not necessary but then i think u would end up compiling that file with the name u provided resulting in a output of. class file with same name u provided and then it will give error.
+ 2
but at compiling time it is not necessary
+ 2
i have one more question on arrays how to find contiguous subarrays of an array....
i posted this question and described it properly butno one answered......i want to know algorithm use for that
+ 1
i have tried it u can try it
+ 1
if sololearn allow pictures i will post it
+ 1
my question is sololearn challenge question say .java file must have same name as class name.......but it is not necessary
+ 1
i lose challenge because of wrong answer of sololearn
+ 1
yes martin u are right but question is not about declaring public
+ 1
yes u are right shobit at execution time class in which main method consist of must be give
+ 1
If you declare your class public, the filename must match the class name. Otherwise this is not mandatory
0
just try it once it will not going to run.
0
it ran or not?
0
i have played a lot with java and if. class file doesnt match with that of class it simply gives error.
0
look suppose ur. java file is not same as the class name then ur code will compile but it will result in a. class file with the name that u have written and will not be the name of class which has main(), at time of execution jvm try to access that class whose name is something else but as u provided different it will end up in not finding it giving error.
0
but still, it can create confusion while running program.