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  What is a built in class?

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  How many classes are there in Java?

Leave a Reply

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