Question
In OOP, what term best describes the relationship where
one object is a part of another but cannot exist independently?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.
Rohit's current age matches Rahul's age from 5 years earlier. If the age of Rohit 10 years from now will be the same as Rahul's age 5 years from now, wh...
The heights (in cm) of 9 basketball players in a tournament are as follows: 178, 182, 175, 180, 184, 179, 177, 181, 183
Find the median height of...
Sohan's father was 32 years old when he was born while his mother was 28 years old when his brother, who is two years younger than him, was born. What i...
Present age of βAβ is 40% more than that of βBβ. If 11 years hence from now, βBβ will be 5 years younger than βAβ, then find the sum of ...
A father is three times as old as his son. After 5 years, the fatherβs age will be twice that of his son. What are their current ages?
B is 2 years older than A and A is 5 years older than C. If the sum of the age of A and C is 25 years, then find the sum of the ages of all three.Β
Present age of βAβ is 50% more than that of βBβ. If 12 years hence from now, βBβ will be 11 years younger than βAβ, then find the sum of...
Present ages of βKβ and βLβ are in the ratio 14:6, respectively. If βtβ years hence from now, βKβ will be twice as old as βLβ, then ...
7 years ago, the age ratio between βMβ and βNβ was 4:5. Present average age of βMβ and βOβ is 70 years. Determine the current age of β...
Three individuals β Ria, Tia, and Mia β are discussing their ages. The age of Ria 8 years ago was one-third of Tiaβs age 4 years from now. The tot...