Can a java file have two classes?

Yes, we can have multiple classes in same java file . But, there is one restriction over here, which is that you can have as many classes in one file but only one public class is allowed. If we try to declare 2 classes as public in the same file, the code will not compile.

Sizin İçin Seçtik  How many classes are too many in Java?

Leave a Reply

Your email address will not be published. Required fields are marked *

Can a java file have two classes?

Yes, we can have multiple classes in same java file . But, there is one restriction over here, which is that you can have as many classes in one file but only one public class is allowed. If we try to declare 2 classes as public in the same file, the code will not compile.

Sizin İçin Seçtik  Does Harvard really have free online courses?

Leave a Reply

Your email address will not be published. Required fields are marked *