0

Can we have more that 1 class in 1 .java file ?

Can we have more that 1 class in 1 .java file ? If possible what will be the name of .java file?

29th Jun 2021, 4:26 AM
Md. Shahriar Kamal Nafiz
Md. Shahriar Kamal Nafiz - avatar
3 Respostas
+ 6
Yes, you can have multiple classes within the same file. However, when done, the additional class(es) cannot be public. Only one class per java file may be public and the file name would reflect this class.
29th Jun 2021, 4:52 AM
ChaoticDawg
ChaoticDawg - avatar
+ 1
Thank you so much
29th Jun 2021, 5:02 AM
Md. Shahriar Kamal Nafiz
Md. Shahriar Kamal Nafiz - avatar
0
if there is class in class ('inner class'), also this class can be public. in SoloLearn you can have all public class in one file, its not correct in java but it is Sololearn trick, where classes are automatic separated to files after send (after 'run' is pressed).
29th Jun 2021, 8:57 AM
zemiak