+ 4

In JAVA does file name and class name must be same or it is recommended?

why so?

18th Jul 2017, 3:14 PM
Ashwaghosh Sadanshiv
Ashwaghosh Sadanshiv - avatar
6 Answers
+ 3
well then if I write two classes in a single java file what should I give the file name?
18th Jul 2017, 3:20 PM
Ashwaghosh Sadanshiv
Ashwaghosh Sadanshiv - avatar
+ 2
@ashwaghosh you have to name .java to that class which will have main method. compiler will automatically make. class file for all classes that you have.
18th Jul 2017, 3:41 PM
shobhit
shobhit - avatar
+ 2
Get file name then run method main() Then example I named one file with "Itaiyo.java" Ah....what kind of that file? Then compile....*wait 1 hour* Run Itaiyo.class This Itaiyo.class will run "new Itaiyo().main(*Some arguments which idk how to read*)" #(I guessed all of that)
18th Jul 2017, 5:50 PM
Yanothai Chaitawat
Yanothai Chaitawat - avatar
+ 2
didn't get it
18th Jul 2017, 5:59 PM
Ashwaghosh Sadanshiv
Ashwaghosh Sadanshiv - avatar
+ 1
yes they must be same or it will cause error
18th Jul 2017, 3:18 PM
Naveed Jeelani Khan
Naveed Jeelani Khan - avatar
0
dont know :)
18th Jul 2017, 3:23 PM
Naveed Jeelani Khan
Naveed Jeelani Khan - avatar