Below you will find pages that utilize the taxonomy term “Java”
Posts
Java: Multiple class declarations in one file
If you already know why the following code fail to compile, then you don’t need to continue reading!
// File: MyClass.java
public class MyClass {
// field, constructor, and
// method declarations
}
public class MyClass2 {
// field, constructor, and
// method declarations
}
However, if you are surprised then continue reading:
Above code fails to compile because there are two public classes declared in a single file.
If you need to define multiple classes in a single file you need to declare only one Public top level class.