Skip to content
Related Articles

Related Articles

C++ | Inheritance | Question 6

View Discussion
Improve Article
Save Article
Like Article
  • Difficulty Level : Hard
  • Last Updated : 28 Jun, 2021




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

(A) No Compiler Error
(B) Compiler Error in line “Base *bp = new Derived;”
(C) Compiler Error in line ” Derived *dp = new Base;”
(D) Runtime Error


Answer: (C)

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


Quiz of this Question

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!