Ask Question

What is the difference between a class and an object?

+4
Answers (1)
  1. 13 October, 15:47
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers