Interview Question
Qus: Explain the difference between a class and an object?
1) Object is an instance of a class whereas Class is a blueprint or template from which objects are created.
2) Object is a real world entity such as pen, laptop, mobile, bed, keyboard, mouse, chair etc. whereas Class is a group of similar objects.
3) Object is a physical entity whereas Class is a logical entity.
4) Object is created through new keyword mainly e.g. Student s1=new Student(); whereas Class is declared using class keyword e.g. class Student{}
5) Object is created many times as per requirement whereas Class is declared once.
6) Object allocates memory when it is created whereas Class doesn't allocated memory when it is created.
Answers (2)
Class is the definition of an object
It is a template of the object
It describes all the methods, properties, etc
OBJECT:
An object is an instance of a class.
A class does not become an object unless instantiated
An object is used to access all those properties from the class.
2) Object is a real world entity such as pen, laptop, mobile, bed, keyboard, mouse, chair etc. whereas Class is a group of similar objects.
3) Object is a physical entity whereas Class is a logical entity.
4) Object is created through new keyword mainly e.g. Student s1=new Student(); whereas Class is declared using class keyword e.g. class Student{}
5) Object is created many times as per requirement whereas Class is declared once.
6) Object allocates memory when it is created whereas Class doesn't allocated memory when it is created.