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.
‘A’, ‘B’ and ‘C’ started a business by investing Rs. 2200, Rs. 4000 and Rs. 3000, respectively. After 4 months, ‘B’ left and ‘A’ and...
Bina and Bimal started a business by investing Rs. 25,000 and Rs. 35,000 respectively. Bina also worked as the active manager and for that, she is entit...
A, B and C invested in partnership. A invest Rs.8000 for 7 months, B invests Rs.6000 for 4 months and C invests Rs.12000 for 2 months. C is working part...
Determine the initial investment made by 'Adam' if both 'Adam' and 'Zampa' jointly invested Rs. 7000 in a startup business. After 7 months, 'Adam' added...
A started a retail business by investing Rs.45,000. After six months B joined him with a capital of Rs.75,000. After 2 years, they earned a profit of ...
‘A’, ‘B’ and ‘C’ entered into a partnership by making investments in the ratio 5:3:9, respectively. At end of the year, if the difference be...
- ‘C’ and ‘D’ jointly started a business. ‘C’ invested an amount which was 20% more than ‘D’. However, ‘D’ invested his capital for 10% l...
A starts business with Rs.12000 and after 8 months, B joins with A as his partner. After a year, the profit divided in the 5:7. What is B’s contribut...
Pritam and Neha invested in a business in the ratio 8 : 5. If 9% of the total profit goes to charity and Pritam’s share is Rs. 18200, the tota...
‘M’ started a business with an investment of Rs. 2900. After 2 months ‘N’ joins the business with an investment of Rs. 2400. If the total profit...