Question:

What is a class?

Answer:

[Probably this would be the first question for a Java/c++ technical interview for freshers and sometimes for experienced as well. Try to give examples when you answer this question.]

Class defines a datatype, it's type definition of category of thing(s). But a class actually does not define the data, it just specifies the structure of data. To use them you need to create objects out of the class. Class can be considered as a blueprint of a building, you can not stay inside blueprint of building, you need to construct building(s) out of that plan. You can create any number of buildings from the blueprint, similarly you can create any number of objects from a class.

class Vehicle
{
    public:
        int numberOfTyres;
        double engineCapacity;
        void drive(){
            // code to drive the car
        }
};

 


Keywords:

© 2017 QuizBucket.org