Association Aggregation Composition Interview Questions
What is the difference between association, aggregation, and composition in UML/OOP? — spoken sample answer for Indian interviews.
- 5Questions with answers
- 3Difficulty levels
Questions (5)
Browse beginner, intermediate, and advanced questions with answers — hide them when you want to self-test.
What is the difference between association, aggregation, and composition in UML/OOP?
Association means two objects know each other, like a teacher and a student. Neither owns the other's lifetime. Aggregation is has-a, but the part can live on its own — a department has professors, and professors still exist if the department is dissolved. Composition is has-a with ownership — a house has rooms; if I destroy the house, the rooms go with it. In a database that often means cascade delete. I use this when modeling, not as trivia. If the lifetime is independent, I do not draw a filled composition diamond.
One-line examples for all three.
Association: Student and Course, neither owns the other's life. Aggregation: Department has Professors who can exist elsewhere. Composition: House and Room — destroy the house, rooms go. I am sharp on composition equals owned lifecycle. That maps to cascade delete.
How do these show up as foreign keys?
Composition often means cascade delete: order_lines die with order. Aggregation might be a nullable FK. Association is a join table or an FK without cascade. I would not cascade-delete customers when I delete a department.
Is a car and its engine composition?
If the engine is destroyed with the car, composition. If I can move the engine to another car, aggregation. Real engines are often aggregation. I ask about lifecycle, not the English word has.
Can many-to-many be composition?
Almost never. Composition is exclusive ownership. Students and courses are a junction table. A filled diamond on many-to-many is a UML smell.
Practice with AI mock interviews
Run OOP mock interviews with AI follow-ups, instant feedback, and analytics on AiLx.
Free to start · No credit card required