What relationship does public inheritance from a base class represent in C++?
Correct answer
C. An is-a relationship, where the derived type specialises the base
14 views
C. An is-a relationship, where the derived type specialises the base
14 views
Public inheritance expresses is-a: a derived object can be used wherever a base object is expected, which is what makes polymorphism through base pointers valid. Composition, where the base is a member object, models has-a and is usually preferred when the relationship is not a genuine specialisation. Private inheritance makes the base an implementation detail and does not expose the is-a conversion publicly.
Asked in: NTS, PPSC IT, Campus Interviews
Not sure why the answer is C? Ask here and get an explanation.