ЁЯУв Too many exams? DonтАЩt know which one suits you best? Book Your Free Expert ЁЯСЙ call Now!


    Question

    In OOP, what term best describes the relationship where

    one object is a part of another but cannot exist independently?
    A Composition Correct Answer Incorrect Answer
    B Aggregation Correct Answer Incorrect Answer
    C Inheritance Correct Answer Incorrect Answer
    D Polymorphism Correct Answer Incorrect Answer
    E Association Correct Answer Incorrect Answer

    Solution

    Composition is a "has-a" relationship where one object contains another, and the contained object cannot exist independently of the parent. 1. Dependency: For instance, an engine is part of a car and cannot function independently outside of it. 2. Tight Coupling: The lifecycle of the child object depends entirely on the parent object. If the parent is destroyed, the child is destroyed too. 3. Reusability: Composition fosters code reuse by enabling modular design without strict inheritance hierarchies. Option A exemplifies composition through its strong containment relationship, central to creating complex, interdependent systems. Why Other Options Are Incorrect: тАв B) Aggregation: Denotes a weaker "has-a" relationship, where components can exist independently. тАв C) Inheritance: Refers to property sharing, not containment. тАв D) Polymorphism: Focuses on method behavior variability. тАв E) Association: A general relationship without specific containment rules.

    Practice Next
    More Data Analytics Languages Questions
    ask-question