31.1k views
3 votes
What is the difference between a class and an object?

1 Answer

2 votes

Step-by-step explanation:

The difference between a class and an object is very simple a class is a template for objects.A class contains objects,methods,constructors,destructors. While an object is a member of the class or an instance of the class. for ex:-

#include<iostream>

using namespace std;

class car

{

public:

string color;

int numgears;

int engine capacity_cc;

bool ispetrol;

car(string color,int numgears,int engine capacity_cc,bool ispetrol)

{

this->color=color;

this->numgears=numgears;

this->capacity_cc=capacity_cc;

this->ispetrol=ispetrol;

}

};

int main()

{

car volvo = new car("red",6,2500,false);

return 0;

}

In the example we have class car and it's object is volvo.

User Ray Vahey
by
5.4k points