📢 Too many exams? Don’t know which one suits you best? Book Your Free Expert 👉 call Now!

  • google app store apple app store
  • ✖

      Question

      Consider the following C++ code:     class Base

      {     public:         void show() { std::cout
      A Base::show Correct Answer Incorrect Answer
      B Derived::show Correct Answer Incorrect Answer
      C Compilation Error Correct Answer Incorrect Answer
      D Runtime Error Correct Answer Incorrect Answer
      E Nothing, the program will not execute. Correct Answer Incorrect Answer

      Solution

      In C++, if a base class method is not declared virtual, method calls through a base class pointer (or reference) are resolved at compile time based on the type of the pointer(Base), not the actual object it points to (Derived). To achieve Derived::show output, Base::show() would need to be declared virtual.

      Practice Next
      ask-question