Question
Which type of relationship between classes in OOP is
best represented when one class is a part of another class but can exist independently?Solution
Aggregation is a type of association that represents a "whole-part" relationship between two classes. The key characteristic is that the part (child object) can exist independently of the whole (parent object). For instance, in a Team class and Player class, a Player can exist without being associated with a Team . Aggregation is implemented by using references, where one class has an attribute referencing another class. This design principle promotes flexibility and modularity. Aggregation is often represented with a hollow diamond in UML diagrams. Why Other Options Are Wrong Option B : "Inheritance" Inheritance represents an "is-a" relationship, not a "whole-part" relationship. It is used to share functionality between classes, not to model part-whole dependencies. Option C : "Composition" Composition is similar to aggregation but with a crucial difference: the part cannot exist independently of the whole. For example, a Car and its Engine share a composition relationship because an engine has no meaning outside the car. Option D : "Association" Association is a broader concept that describes any relationship between classes. Aggregation is a specific type of association. Option E : "Polymorphism" Polymorphism is unrelated to class relationships and focuses on method behavior.
Six persons M, N, Q, W, T and Y are arranged according to their height. Find the second shortest person.
I) M is taller than T but shorter th...
Eight persons, P, Q, R, S, T, U, V and W are sitting in a row. All of them are facing the north. Who is sitting at the extreme left end?
Statem...
S, B, T, H, M and R are sitting around a circular table. S, Band M are males while the rest are females. Who are the neighbours of S?
I. T does n...
The question given below consists of some statements given below it. You have to decide whether the data provided in the statements are sufficient to a...
In a certain code language, "made my work good" is written as "ta la sa pa". How is "good" written in the code language?
I. "his work is good" is...
Among 6 friends, P, Q, R, S, T and U, who is third tallest?
I. R is taller than only S.
II. T is taller than P and U but is not the talles...
How is Gaurav related to Preeti?
I. Shekhar and Gaurav are the two sons of Raj and Preeti is the daughter of Shekhar.
II. Preeti’s ...
Five persons D, E, F, G, and H are attending the seminar on five different days of the same week starting from Monday to Friday. G attends the seminar o...
Among five states M, N, O, P and Q, M is in which direction with respect to N?
I.M is to the west of O, which is to the south of Q. N is to th...
Six people, J, K, L, M, N, and O, went to Chennai, on different days from Sunday to Friday, of the same week of February, 2024. How many persons went t...