Ask Question
9 May, 18:03

What is the difference between a class and an object?

+1
Answers (1)
  1. 9 May, 21:41
    0
    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

    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.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “What is the difference between a class and an object? ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers