Back-End Programming Exam  >  Back-End Programming Tests  >  Learn to Program with C++: Beginner to Expert  >  Test: Inheritence And Polymorphism - 1 - Back-End Programming MCQ

Test: Inheritence And Polymorphism - 1 - Back-End Programming MCQ


Test Description

10 Questions MCQ Test Learn to Program with C++: Beginner to Expert - Test: Inheritence And Polymorphism - 1

Test: Inheritence And Polymorphism - 1 for Back-End Programming 2024 is part of Learn to Program with C++: Beginner to Expert preparation. The Test: Inheritence And Polymorphism - 1 questions and answers have been prepared according to the Back-End Programming exam syllabus.The Test: Inheritence And Polymorphism - 1 MCQs are made for Back-End Programming 2024 Exam. Find important definitions, questions, notes, meanings, examples, exercises, MCQs and online tests for Test: Inheritence And Polymorphism - 1 below.
Solutions of Test: Inheritence And Polymorphism - 1 questions in English are available as part of our Learn to Program with C++: Beginner to Expert for Back-End Programming & Test: Inheritence And Polymorphism - 1 solutions in Hindi for Learn to Program with C++: Beginner to Expert course. Download more important topics, notes, lectures and mock test series for Back-End Programming Exam by signing up for free. Attempt Test: Inheritence And Polymorphism - 1 | 10 questions in 20 minutes | Mock test for Back-End Programming preparation | Free important questions MCQ to study Learn to Program with C++: Beginner to Expert for Back-End Programming Exam | Download free PDF with solutions
Test: Inheritence And Polymorphism - 1 - Question 1

What does inheriatance allows you to do?

Test: Inheritence And Polymorphism - 1 - Question 2

What is the output of the program?
#include <iostream>  
using namespace std;
 
class Base1 {
 public:
     ~Base1()  { cout << " Base1's destructor" << endl; }
};
   
class Base2 {
 public:
     ~Base2()  { cout << " Base2's destructor" << endl; }
};
   
class Derived: public Base1, public Base2 {
   public:
     ~Derived()  { cout << " Derived's destructor" << endl; }
};
   
int main()
{
   Derived d;
   return 0;
}

Detailed Solution for Test: Inheritence And Polymorphism - 1 - Question 2

Destructors are always called in reverse order of constructors.

1 Crore+ students have signed up on EduRev. Have you? Download the App
Test: Inheritence And Polymorphism - 1 - Question 3

How many types of inheritance are there in c++?

Detailed Solution for Test: Inheritence And Polymorphism - 1 - Question 3

There are five types of inheritance in c++. They are single, Multiple, Hierarchical, Multilevel, Hybrid.

Test: Inheritence And Polymorphism - 1 - Question 4

What is the output of the program?

Detailed Solution for Test: Inheritence And Polymorphism - 1 - Question 4

The print function is not present in class R. So it is looked up in the inheritance hierarchy. print() is present in both classes P and Q, which of them should be called? The idea is, if there is multilevel inheritance, then function is linearly searched up in the inheritance hierarchy until a matching function is found.

Test: Inheritence And Polymorphism - 1 - Question 5

How many types of constructor are there in C++?

Detailed Solution for Test: Inheritence And Polymorphism - 1 - Question 5

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

Test: Inheritence And Polymorphism - 1 - Question 6

What is the output of the program?

#include<iostream>
using namespace std;
class Base {};
class Derived: public Base {};
int main()
{
    Base *bp = new Derived;
    Derived *dp = new Base;
}

Detailed Solution for Test: Inheritence And Polymorphism - 1 - Question 6

A Base class pointer/reference can point/refer to a derived class object, but the other way is not possible.

Test: Inheritence And Polymorphism - 1 - Question 7

What should be the name of constructor?

Test: Inheritence And Polymorphism - 1 - Question 8

What is the output of the program?

#include<iostream>
using namespace std;
 
class Base
{
public:
    int fun()  { cout << "Base::fun() called"; }
    int fun(int i)  { cout << "Base::fun(int i) called"; }
};
 
class Derived: public Base
{
public:
    int fun() {  cout << "Derived::fun() called"; }
};
 
int main()
{
    Derived d;
    d.fun(5);
    return 0;
}

Detailed Solution for Test: Inheritence And Polymorphism - 1 - Question 8

If a derived class writes its own method, then all functions of base class with same name become hidden, even if signaures of base class functions are different. In the above question, when fun() is rewritten in Derived, it hides both fun() and fun(int) of base class.

Test: Inheritence And Polymorphism - 1 - Question 9

What is meant by polymorphism?

Detailed Solution for Test: Inheritence And Polymorphism - 1 - Question 9

Polymirphism is literally means class having many forms.

Test: Inheritence And Polymorphism - 1 - Question 10

Output of following program?
#include <iostream>
#include<string>
using namespace std;
 
class Base
{
public:
    virtual string print() const
    {
        return "This is Base class";
    }
};
 
class Derived : public Base
{
public:
    virtual string print() const
    {
        return "This is Derived class";
    }
};
 
void describe(Base p)
{
    cout << p.print() << endl;
}
 
int main()
{
    Base b;
    Derived d;
    describe(b);
    describe(d);
    return 0;
}

Detailed Solution for Test: Inheritence And Polymorphism - 1 - Question 10

Note that an object of Derived is passed in describe(d), but print of Base is called. The describe function accepts a parameter of Base type. This is a typical example of object slicing, when we assign an object of derived class to an object of base type, the derived class object is sliced off and all the data members inherited from base class are copied. Object slicing should be ovoided as there may be surprising results like above. As a side note, object slicing is not possible in Java. In Java, every non-primitive variable is actually a reference.

73 videos|7 docs|23 tests
Information about Test: Inheritence And Polymorphism - 1 Page
In this test you can find the Exam questions for Test: Inheritence And Polymorphism - 1 solved & explained in the simplest way possible. Besides giving Questions and answers for Test: Inheritence And Polymorphism - 1, EduRev gives you an ample number of Online tests for practice
Download as PDF