Classes & Objects


  1. Which of the following can derived class inherit?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    both members & function


  1. Where is the derived class is derived from?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    Because derived inherits functions and variables from base.



  1. Pick out the correct statement.











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    Destructors are automatically invoked when a object goes out of scope or when a dynamically allocated object is deleted. Inheritance does not change this behavior. This is the reason a derived destructor cannot invoke its base class destructor.


  1. What is the output of this program?
    #include <iostream>
    using namespace std;
    class Example
    {
    public:
    Example()
    {
    cout << "N::N()" << endl;
    }
    Example( Example const & )
    {
    cout << "N::N( N const & )" << endl;
    }
    Example& operator=( Example const & )
    {
    cout << "N::operator=(N const &)" << endl;
    }
    };
    Example function()
    {
    Example temp;
    return temp;
    }
    int main()
    {
    Example p = function();
    return 0;
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    As we are passing the object without any attributes it will return as N::N().



  1. What is the output of this program?
    #include <iostream>
    using namespace std;
    class First
    {
    public:
    First(int num1 )
    {
    cout << num1 <<" ";
    }
    };
    class Second: public First
    {
    public:
    Second(int num1, double num2)
    : First(num1)
    {
    cout << num2 <<" ";
    }
    };
    class Third: public Second
    {
    public:
    Third(int num1, double num2, char ch)
    : Second(num1, num2)
    {
    cout < }
    };
    int main()
    {
    Third object(6, 5.35, 'I');
    return 0;
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: E

    In this program, We are passing the value and manipulating by using the derived class.