Question

    What type of relationship is represented by

    Aggregation in Object-Oriented Programming?
    A "Is-a" relationship Correct Answer Incorrect Answer
    B "Has-a" relationship with shared ownership Correct Answer Incorrect Answer
    C "Has-a" relationship with exclusive ownership Correct Answer Incorrect Answer
    D Parent-child relationship Correct Answer Incorrect Answer
    E Object-to-object message communication Correct Answer Incorrect Answer

    Solution

    Aggregation is a "has-a" relationship where one object is composed of other objects, but the lifecycle of the contained objects is independent of the containing object . For example, a Teacher class might be associated with a School class, but even if the School object is destroyed, the Teacher object can continue to exist. Aggregation emphasizes shared ownership and loosely coupled associations, making it useful for scenarios requiring flexibility in object dependencies. Why Other Options Are Incorrect :

    1. "Is-a" relationship : This refers to Inheritance , where a subclass derives from a parent class.
    2. "Has-a" relationship with exclusive ownership : This describes Composition , where the contained objects' lifecycle is tied to the container.
    3. Parent-child relationship : This typically relates to Inheritance or tree structures , not Aggregation.
    4. Object-to-object message communication : This aligns with Message Passing , which focuses on interaction between objects rather than relationships

    Practice Next