Skip to content
Related Articles

Related Articles

C++ | Inheritance | Question 8
  • Difficulty Level : Medium
  • Last Updated : 15 Oct, 2013




#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;
}


(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

Attention reader! Don’t stop learning now. Get hold of all the important C++ Foundation and STL concepts with the C++ Foundation and STL courses at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :