Difference between Class and Object in OOPS

Difference between Class and Object in oops:

Sr# Class Object
1. A class is a way of binding the data members and the associated methods into single unit. Class variable is known as an object.
2. Whenever we start execution of a java application, JVM will load the class into the main memory of the computer only once with the help of Class Loader Sub System (a JVM Tool). After loading the class, we can create n# of objects as per requirements.
3. When the class is defined, there is no memory space for the data members of the class. When the object is defined, data members of the class will get the memory space.
4. In every java application, class will exist only once. In a java application, there is a possibility of creating either single or multiple objects, depending upon the requirements.
5. Class is a blueprint or template from which objects are created. It is a instance of class.
6. Class is a group of similar objects. Object is a real world entity such as computer, chalk, phone, mobile etc.
7. It is a logical entity. It is a physical entity.
8. Class is created with the help of class keyword.

e.g.:

class Car {}

Object is created with the help of new keyword.

e.g.:

Car c = new Car();

9. Class is declared once. Object is created many times as it required.
10. Class doesn’t allocated memory when it is created. Objects allocated memory whenever it is created.
11. In java we can define class only with the help of class keyword. In java we can define object by many ways like with the help of new keyword, newInstance () , factory () , clone(), and deserialization etc.

Leave a Reply