How many public classes are allowed in a java file?
you can have more than one public outer class in a java file
you can have more than one class in a given java file, where only one public class in it.
if you want to have more than one public class, then you have to define them in their own file.
you can't write more than one class in a file
Basic java rule says that, a file should have only one public class.
Every public class should be defined in its own file.
Note: But a file can have other non public classes in it.
So, You can't have more than one public outer class in a given java file. if you want, you have to define them in their own file. but a java file can have multiple outer classes in that where there is only one public class which is same as the file name.
Back To Top