Question

The following C++ code has a compilation error. How can you correct it to properly use the abstract base class `Printer`? #include class Printer { public:     virtual void print() = 0; }; class LaserPrinter : public Printer { public:     void print() {         std::cout << "Printing with LaserPrinter" << std::endl;     } }; int main() {     Printer* p = new LaserPrinter();     p->print();     delete p;     return 0; }

A The code is already correct; there is no error.
B Change `virtual void print() = 0;` to `void print() {};`.
C Remove the `override` keyword from `LaserPrinter::print()`.
D Make `LaserPrinter` an abstract class.
E Change `Printer* p = new LaserPrinter();` to `LaserPrinter* p = new LaserPrinter();`.
Practice Next

Hey! Ask a query

🎓
Think You're Ready for RBI Grade B?
RBI Grade B 2026 Phase 1 Memory Based Paper
  • 200 Questions with Detailed Solutions
  • Section-wise Coverage (GA, English, Quant & Reasoning)