C++ | Inheritance | Question 9

#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.Base::fun(5);
    return 0;
}

(A) Compiler Error
(B) Base::fun(int i) called


Answer: (B)

Explanation: We can access base class functions using scope resolution operator even if they are made hidden by a derived class function.

Quiz of this Question

GATE CS Corner    Company Wise Coding Practice

Recommended Posts:



0 Average Difficulty : 0/5.0
No votes yet.