Java – Defining classes in Java files


I have found one error in my Java program:

The public type abc class must be defined in its own class

How can I resolve this error? I am using Eclipse. I am new to Java programming.

Best Solution

Each source file must contain only one public class. A class named ClassName should be in a file named, and only that class should be defined there.

Exceptions to this are anonymous and inner classes, but understanding you are a beginner to Java, that is an advanced topic. For now, keep one class per file.

Answering your addition: it is OK to inherit classes and that's totally fine. This does not matter, each class should still have its own file.