Class and Object
Class
- A class is simply a representation of a type of object.
- It is the blueprint/ plan/ template that describe the details of an object.
- It contains state(instance variables) and behaviour (methods).
- A template that describes the kinds of state and behaviour that objects of its type support.
Example:-
Class Employee
{
//code......
}
Object:-
- An Object is a real world entity.
- An object can be considered a "thing" that can perform a set of related activities.
- The set of activities that the object performs defines the object's behavior.
For Example:
amit is an object of class Employee.
Employee tkhts = new Employee();
Instance Member and Class Member
Instance Member:-
- Instance variables are non-static.
- There is one occurrence of an instance variable in each class instance.
- It is also known as a member variable or a field.
Example of an instance variable:-
class Employee
{
int id;
//code......
//code......
}
Class Member:-
- Class variables are called static variables.
- There is only one occurrence of a class variable per JVM per class loader.
- When a class is loaded the class variables are initialized.
- A static variable is used in the singleton Design pattern.
- A static variable is used with a final modifier to define constants.
Example of a class variable
class Employee
{
static int id;
//code......
//code......
}


