logo

Question detail

A class diagram contains a single inheritance relationship, one composition relationship and one aggregation relationship. Explain how these three relationships differ, state the UML notation for the two whole-part relationships, and describe how polymorphism can be used in an object-oriented program involving inheritance.

Try the question, check the answer, then read the explanation to understand the curriculum point.

At a glance

Question

Type

practice

Style

Topic

Programming paradigms

Exam-style question

Try this first

A class diagram contains a single inheritance relationship, one composition relationship and one aggregation relationship. Explain how these three relationships differ, state the UML notation for the two whole-part relationships, and describe how polymorphism can be used in an object-oriented program involving inheritance.

Model answer

What a good answer should say

  • Inheritance is a relationship in which one class derives from another class and can use or extend characteristics and behaviours from the other class.
  • Composition is a whole-part relationship represented by a black diamond line in UML.
  • Aggregation is also a whole-part relationship but is represented by a white diamond line.
  • Polymorphism allows objects associated with related classes to respond through a common class-based relationship while providing class-specific behaviour.

Explanation

Why this works

The answer must distinguish inheritance from the two whole-part relationships, identify black diamond for composition and white diamond for aggregation, and connect polymorphism with related classes and class-specific behaviour. Mentioning overriding is relevant because it is an object-oriented concept in the specification and can support polymorphic behaviour.

Common mistake

No common mistake is linked to this question yet.

Related flashcards

No flashcards are published for this page yet.

Related practice questions

No questions are published for this page yet.