Skip to content
Related Articles

Related Articles

C++ | Virtual Functions | Question 14
  • Difficulty Level : Medium
  • Last Updated : 05 Jan, 2014

Predict the output of following C++ program

using namespace std;
class Base
    virtual void show() { cout<<" In Base \n"; }
class Derived: public Base
    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

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 :