C++ | Inheritance | Question 8
#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; } |
chevron_right
filter_none
(A) Base::fun(int i) called
(B) Derived::fun() called
(C) Base::fun() called
(D) Compiler Error
Answer: (D)
Explanation: 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.
Quiz of this Question
Recommended Posts:
- C++ | Inheritance | Question 1
- C++ | Inheritance | Question 13
- C++ | Inheritance | Question 7
- C++ | Inheritance | Question 11
- C++ | Inheritance | Question 6
- C++ | Inheritance | Question 12
- C++ | Inheritance | Question 5
- C++ | Inheritance | Question 4
- C++ | Inheritance | Question 2
- C++ | Inheritance | Question 9
- C++ | Inheritance | Question 3
- C++ | Inheritance | Question 14
- C++ | Inheritance | Question 10
- Java | Inheritance | Question 1
- Java | Inheritance | Question 2



