Complete the code to declare a virtual function in the base class.
class Base { public: virtual void [1]() { std::cout << "Base function" << std::endl; } };
The method name display is used as the virtual function in the base class.
Complete the code to override the base class method in the derived class.
class Derived : public Base { public: void [1]() override { std::cout << "Derived function" << std::endl; } };
The derived class overrides the display method from the base class.
Fix the error in the code by completing the method declaration to enable overriding.
class Base { public: [1] void display() { std::cout << "Base function" << std::endl; } };
virtual keyword, which disables overriding.The method must be declared with the virtual keyword to allow overriding.
Fill both blanks to correctly override the base class method and call it from the derived class.
class Derived : public Base { public: void [1]() override { Base::[2](); std::cout << "Derived override" << std::endl; } };
The derived class overrides display and calls the base class display method.
Fill all three blanks to create a base class with a virtual method, override it in the derived class, and call the method via a base pointer.
class Base { public: [1] void display() { std::cout << "Base display" << std::endl; } }; class Derived : public Base { public: void [2]() override { std::cout << "Derived display" << std::endl; } }; int main() { Base* ptr = new Derived(); ptr->[3](); delete ptr; return 0; }
The base class method is declared virtual. The derived class method uses override. The method called via pointer is display.