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.
Swati started from her house towards west. After walking a distance of 25 m, she turned to the right and walked 20 m. She then again turned to the right...
Rohit eats more than Ankit, Shubham eats less than Prabhu but more than Ankit. Rohit eats less than Shubham. Who eats the most in the group?
Starting from shop, Neha walks 12km towards west. He then turned right and walks 15km. Then he turned left and walks 8km to reach parlour. From there, h...
Nitin walks 20 km Southwards, then turns right and walks 20 km. he then turns left and walks 20 km. He takes a 60 degree turn rightwards and walks st...
What is the shortest distance between J and N?
Answer the questions based on the information given below.
Riyansh starts from his School and walks towards east direction for 10m. Then he tur...
What is the position of T with respect to W?
Point C is in which direction with respect of Point B?
In which direction is Alok’s house with respect to Sameer’s house?
If K is northeast of C, then what is the distance between K and C?