Skip to content
Related Articles

Related Articles

Improve Article

Difference between Class and Object

  • Last Updated : 24 Jun, 2021

In this article, we will discuss the differences between the class and an object.

Class: A class is the building block that leads to Object-Oriented Programming. It is a user-defined data type, that holds its own data members and member functions, which can be accessed and used by creating an instance of that class. It is the blueprint of any object.

For Example: Consider the Class of Account. There may be many accounts with different names and types but all of them will share some common properties, as all of them will have some common attributes like balance, account holder name, etc. So here, Account is the class, and the balance, the account holder’s name is their property.

Object: An object is an instance of a class. All data members and member functions of the class can be accessed with the help of objects. When a class is defined, no memory is allocated but when it is instantiated (i.e. an object is created), memory is allocated. For example, considering the objects for the Account class is Saving account, Current account, etc.

Difference Between Class And Object:



There are many differences between object and class. Some differences between object and class are given below:

S. No.ClassObject
1Class is used as a template for declaring and 
creating the objects.      
An object is an instance of a class.
2When a class is created, no memory is allocated.Objects are allocated memory space whenever they are created.
3The class has to be declared only once.An object is created many times as per requirement.
4A class cannot be manipulated as they are not
available in the memory.
Objects can be manipulated.
5A class is a logical entity.An object is a physical entity.
6It is declared with the class keywordIt is created with a class name in C++ and 
with the new keywords in Java.
7Class does not contain any values which 
can be associated with the field.
Each object has its own values, which are
associated with it.
8A class is used to bind data as well as methods together as a single unit.Objects are like a variable of the class.
9

Syntax for Declaring Class in C++:

class <classname> {

};

Syntax for Instantiating an object for a Class in C++:

class Student {

   public:

      void put(){



          cout<<“Function Called”<<endl;

      }

};   // The class is declared here

int main(){

         Student s1;   // Object created

         s1.put();

}

10Example: BikeExample: Ducati, Suzuki, Kawasaki
My Personal Notes arrow_drop_up
Recommended Articles
Page :