📢 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: #include

      class Base { public:     virtual void show() = 0; }; class Derived : public Base { public:     void show() override {         std::cout
      A `Derived::show()` Correct Answer Incorrect Answer
      B `Base::show()` Correct Answer Incorrect Answer
      C A compile-time error indicating that `Base` is an abstract class. Correct Answer Incorrect Answer
      D A runtime error. Correct Answer Incorrect Answer
      E No output, but the program would terminate successfully. Correct Answer Incorrect Answer

      Solution

      o In C++, Base is declared with virtual void show() = 0;, which makes show() a pure virtual function. o Any class that contains one or more pure virtual functions is an abstract class. o Abstract classes cannot be instantiated directly. Attempting to create an object of an abstract class (like Base b;) will result in a compile-time error. The compiler will typically issue a message similar to "cannot declare variable 'b' to be of abstract type 'Base'" or "cannot instantiate abstract class 'Base'".

      Practice Next
      ask-question