Can there be multiple classes in Java | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Can there be multiple classes in Java

like c++ can have as many classes as you want... is it same with Java?

5th Jul 2018, 10:06 PM
Omkar Gurav
Omkar Gurav - avatar
4 Answers
+ 3
Yes, you can have multiple classes However, there can only be one public class per .java file. As public classes must have the same name as the source file.
5th Jul 2018, 10:12 PM
Agent
Agent - avatar
+ 4
Thank You.. For your help... But another question so what will happen if we rename the source file?.. Sorry I am just learning java and don't have much knowledge about it so it maybe a silly question...
5th Jul 2018, 10:15 PM
Omkar Gurav
Omkar Gurav - avatar
+ 2
sorry Omkar Gurav I dont know the answer to your second question.
5th Jul 2018, 10:26 PM
Agent
Agent - avatar
+ 2
You will get a compilation error if you try to compile after renaming the file
6th Jul 2018, 12:03 AM
Minnie Mouse
Minnie Mouse - avatar