C++ | Inheritance | Question 9

using namespace std;
class Base {
    int fun()          {    cout << "Base::fun() called";     }
    int fun(int i)     {   cout << "Base::fun(int i) called";  }
class Derived: public Base  {
    int fun()   {     cout << "Derived::fun() called";   }
int main()  {
    Derived d;
    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

My Personal Notes arrow_drop_up

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.