Unified Modeling Language (UML) OOP Quiz Quiz

Challenge your understanding of fundamental Unified Modeling Language (UML) concepts with this object-oriented programming (OOP) quiz. Explore class diagrams, relationships, and key UML notations to reinforce your knowledge of how UML models real-world OOP scenarios.

  1. Class and Object Representation

    In UML class diagrams, which symbol typically represents an object rather than a class, such as an individual instance of 'Car' named 'myCar'?

    1. A rectangle with three compartments labeled 'Methods', 'Attributes', and 'Operations'
    2. An oval with the object's properties inside
    3. A diamond symbol connected to another class
    4. A rectangle with the object name and underline

    Explanation: In UML, objects are represented by rectangles with the object's name underlined to distinguish instances from classes. The second option describes a class rectangle format, not an object. The diamond symbol is used for aggregation relationships, not for representing instances. Ovals represent use cases rather than objects in UML diagrams.

  2. Types of Relationships

    Which type of relationship in UML is best illustrated by a 'Library' class that contains zero or more 'Book' classes, where deleting the library does not necessarily delete the books?

    1. Composition
    2. Association
    3. Inheritance
    4. Aggregation

    Explanation: Aggregation illustrates a whole-part relationship where parts can exist independently, such as books still existing without the library. Association is a general connection, but does not specify whole-part. Composition represents a strong lifecycle dependency, where deleting the whole deletes the parts. Inheritance models is-a relationships, not whole-part ownership.

  3. Multiplicity in Class Diagrams

    If a UML diagram shows a class 'Team' connected to the class 'Player' with a multiplicity of 1..11 at the 'Player' end, what does this indicate about 'Team'?

    1. A Team is a type of Player
    2. A Team must have exactly one Player
    3. Each Player belongs to 1 or 11 Teams
    4. A Team must have between one and eleven Players

    Explanation: A multiplicity of 1..11 means a team must have at least one and no more than eleven players. 'Exactly one Player' would require a multiplicity of 1. The third option reverses the direction and misinterprets multiplicity. The last option incorrectly describes an inheritance relationship, not an association with multiplicity.

  4. UML Inheritance Syntax

    In a UML class diagram, how is inheritance (generalization) visually represented between the 'Vehicle' superclass and the 'Car' subclass?

    1. A solid line with a filled triangle pointing to 'Car'
    2. A dashed line with an open arrow pointing to 'Car'
    3. A line with a filled diamond from 'Vehicle' to 'Car'
    4. A solid line with a hollow triangle arrowhead pointing to 'Vehicle'

    Explanation: Inheritance in UML is depicted by a solid line with a hollow triangle arrowhead pointing from the subclass to the superclass, indicating 'Car' inherits from 'Vehicle'. A dashed line with an open arrow represents dependency or realization, not generalization. A filled diamond indicates composition, while a filled triangle is not a standard inheritance notation in UML.

  5. UML Interface Notation

    Which statement best describes how a UML class diagram shows a class 'Printer' implementing an interface 'Printable'?

    1. A dashed line with a hollow triangle arrowhead from 'Printer' to 'Printable'
    2. A solid line with a circle at the end from 'Printable' to 'Printer'
    3. A solid line with a filled diamond from 'Printable' to 'Printer'
    4. A solid line with an open triangle from 'Printer' to 'Printable'

    Explanation: An implementation relationship is shown by a dashed line with a hollow triangle arrowhead directed toward the interface, indicating 'Printer' implements 'Printable'. Solid lines with filled diamonds represent composition, not implementation. An open triangle on a solid line is for inheritance, not implementation. A line ending with a circle represents a different kind of interface realization, not typical for class diagrams.