Classes & Objects


  1. What is the output of this program?
    #include <iostream>
    using namespace std;
    class Polygon
    {
    protected:
    int W, H;
    public:
    void set_values(int width, int height)
    {
    W = width; H = height;
    }
    };
    class Coutput
    {
    public:
    void output(int i);
    };
    void Coutput::output(int i)
    {
    cout << i <<" ";
    }
    class Rectangle:public Polygon, public Coutput
    {
    public:
    int area()
    {
    return(W * H);
    }
    };
    class Triangle:public Polygon, public Coutput
    {
    public:
    int area()
    {
    return(W * H / 2);
    }
    };
    int main()
    {
    Rectangle Rect;
    Triangle trgl;
    Rect.set_values(5, 2);
    trgl.set_values(5, 2);
    Rect.output(Rect.area());
    trgl.output(trgl.area());
    return 0;
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    In this program, We are calculating the area of rectangle and
    triangle by using multilevel inheritance.


  1. What is meant by container ship?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    class contains objects of other class types as its members



  1. How many types of the constructor are there in C++?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    There are three types of constructor in C++. They are the Default constructor, Parameterized constructor, Copy constructor.


  1. How many constructors can present in a class?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    There can be multiple constructors of the same class, provided they have different signatures.



  1. What should be the name of the constructor?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    same as the class