Skip to content
Related Articles

Related Articles

Save Article
Improve Article
Save Article
Like Article

C++ | Inheritance | Question 9

  • Last Updated : 01 Jun, 2021




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

My Personal Notes arrow_drop_up
Recommended Articles
Page :