CS FundamentalsVery hardProduct-company design interview

An object adapter and a class adapter both make class Legacy fit interface Target. Which statement is correct?

  1. A. An object adapter holds a Legacy instance and delegates to it, so it also works with Legacy's subclasses; a class adapter inherits from Legacy, so it can override Legacy's methods but needs multiple inheritance of implementation
  2. B. Both use inheritance only
  3. C. A class adapter wraps an instance while an object adapter inherits
  4. D. They differ only in name

Correct answer: A. An object adapter holds a Legacy instance and delegates to it, so it also works with Legacy's subclasses; a class adapter inherits from Legacy, so it can override Legacy's methods but needs multiple inheritance of implementation

Composition (object adapter) is more flexible and works in single-inheritance languages like Java; the class adapter binds to one concrete class but can tweak its behaviour by overriding.

More Software Engineering, Git and Cloud Basics questions

Exams that ask this topic