Difference between class and object

Object is an instance of a class. Class is a blueprint or template from which objects are created.
Object is a real world entity such as pen, laptop, mobile, bed, keyboard, mouse, chair etc. Class is a group of similar objects.
Object is a physical entity. Class is a logical entity.
Object is created through new keyword mainly e.g. Student s1=new Student(); Class is declared using class keyword e.g. class Student{}
Object is created many times as per requirement. Class is declared once.
Object allocates memory when it is created. Class doesn’t allocated memory when it is created.
There are many ways to create object in java such as new keyword, newInstance() method, clone() method, factory method and deserialization. There is only one way to define class in java using class keyword.

A class specifies the behavior of its instances.

A class is an instance of a class too (class for a class is named a “metaclass”).

A class is an abstraction. You find a class by finding generic properties applying to a group of objects. Then a class is a template which defines the methods (behavior) and variables (state) to be included in a particular kind of object Recognition of classes (outside classroom) requires experience.

Leave a Reply

Your email address will not be published. Required fields are marked *