C++ | Inheritance | Question 6
#include<iostream> using namespace std; class Base {}; class Derived: public Base {}; int main() { Base *bp = new Derived; Derived *dp = new Base; } |
chevron_right
filter_none
(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.
Recommended Posts:
- C++ | Inheritance | Question 8
- C++ | Inheritance | Question 5
- C++ | Inheritance | Question 3
- C++ | Inheritance | Question 7
- C++ | Inheritance | Question 2
- C++ | Inheritance | Question 1
- C++ | Inheritance | Question 9
- C++ | Inheritance | Question 14
- C++ | Inheritance | Question 10
- C++ | Inheritance | Question 11
- C++ | Inheritance | Question 12
- C++ | Inheritance | Question 13
- C++ | Inheritance | Question 4
- Java | Inheritance | Question 8
- Java | Inheritance | Question 9



