How to create a class in Java?
A class is a specification or blueprint from which individual objects are created. A class contains fields that represent the object's states and methods that defines the operations that are possible on the objects of the class.
The file name that contains the definition of a class is always the same as the public class name and the extension is .java to identify that the file contains a Java source code.
A class has constructors, a special method that is used to create an instance or object of the class. When no constructor define a default constructor will be used. The constructor method have the same name with the class name without a return value. The constructors can have parameters that will be used to initialize object's states.
Here is a Person.java file that defines the Person class.
Here is a ClassExample.java file that defines the ClassExample class that use the Person class.