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  1 TWT Coin kaç dolar?

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  Can you implement a class in Java?

Leave a Reply

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