ProgrammingHardGATE CS · TCS NQT Prime · Product Company SDE

A PaymentMethod type requires every concrete implementation to provide charge() and refund(), but there is no shared implementation at all to reuse between them. Which design fits best?

  1. A. A single concrete class with both methods implemented directly
  2. B. A pure interface (or, in C++, a class with only pure virtual functions) declaring charge() and refund()
  3. C. A set of unrelated static utility methods
  4. D. An abstract class whose constructor performs heavy shared setup logic

Correct answer: B. A pure interface (or, in C++, a class with only pure virtual functions) declaring charge() and refund()

With no shared implementation to reuse, a pure contract (interface, or a C++ class of only pure virtual functions) is the right tool; an abstract class is for sharing common code, which there is none of here.

More OOP with C++ and Java questions

Exams that ask this topic