Open In App
Related Articles

C++ | Virtual Functions | Question 14

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report
Predict the output of following C++ program
#include<iostream>
using namespace std;
  
class Base
{
public:
    virtual void show() { cout<<" In Base \n"; }
};
  
class Derived: public Base
{
public:
    void show() { cout<<"In Derived \n"; }
};
  
int main(void)
{
    Base *bp = new Derived;
    bp->Base::show();  // Note the use of scope resolution here
    return 0;
}

                    
(A) In Base (B) In Derived (C) Compiler Error (D) Runtime Error

Answer: (A)

Explanation: A base class function can be accessed with scope resolution operator even if the function is virtual.

Quiz of this Question

Last Updated : 28 Jun, 2021
Like Article
Save Article
Share your thoughts in the comments
Similar Reads