The class and object concepts are included in the Object Oriented Programming Model to easily represent the real world entities in the software programming. We can make following definitions of a class in Java.
Definition 1:-
A Java class is a logical entity which represents a category.
Explanation:
Everythings around us are logical entities(Fruit, Car, Pen, Bike, etc) and physical entities( A Mango, A Honda Accord, Cello Fingergrip, Honda Unicorn, etc). A class is a logical entity because we always use class to represents a category like a Fruit; fruit is logical, we cannot see or eat fruit but we can see or eat a mango or a banana which are physical entities and belongs to the fruit category.
Similarly, we do not see car because it is logical, but we see and drive a Honda Accord which is a physical entity and comes under the car category. We create multiple objects of a class to represent similar type of physical entities.
Definition 2:-
A class in Java is a blueprint/model from which objects are created.
Explanation:
Consider you have a blueprint of a house; you can create or build same type (bunglow, apartment, etc) of houses but with different parameters (color of house, location address, etc).
Here the blueprint of a house is a class and multiple houses constructed with different colours and locations are objects.
A class is a model of an object because by just looking at the data members and member methods of a class we can predict what an object will contain even before creating that object. A class contain fields and methods to describe the state and behaviour of an object.
Syntaxes:-
Class keyword is required to declare a class. Following are syntaxes of a class in Java:
Syntax 1:
[access modifiers]class ClassName
{
// class body
}
Syntax 2:
[access modifiers]class ClassName
{
// class body
};
Note: Writing ‘;’ semicolon at the end of class body is optional in Java.
Note: A class name can be any valid identifier, but should not be a reserved keyword.
class HelloJava
{
// class body
}
Concrete class- Any normal class which does not have any abstract method or a class which has implementation of all the methods of its parent class or interface and its own methods is a concrete class.
Abstract class- A class declared with abstract keyword and have zero or more abstract methods is known as abstract class. The abstract classes are incomplete classes therefore to use you strictly need to extend the abstract classes to a concrete class.
Final class- A class declared with final keyword is a final class, and it cannot be extended by another class, for example java.lang.System class.
POJO class- A class which contains only private variables and setter and getter methods to use those variables is called POJO (Plain Old Java Object) class. It is a fully encapsulated class.
Static class- Static classes are nested classes, means a class declared within another class as a static member is called a static class.
Inner Class- A class declared within another class or method is called an inner class.