Java HAS-A Relationship Explained

🚀 Java – Interview Question 📌 Question: What is HAS-A Relationship in Java (Aggregation & Composition)? 🔹 HAS-A Relationship HAS-A represents a containment relationship in OOP. ✔ One class contains another class as a member (instance variable). ✔ Implemented using object reference. ✔ Promotes code reusability and modular design. Example: 👉 A Car HAS-A Engine 🔹 Aggregation (Weak Association) ✔ Represents a weak relationship ✔ The contained object can exist independently ✔ Also called a “uses-a” relationship Example: A Student HAS-A Address (Address can exist without Student) 🔹 Composition (Strong Association) ✔ Represents a strong relationship ✔ The contained object cannot exist independently ✔ If container is destroyed → contained object is also destroyed 💡 Interview Key Points: ✔ HAS-A = Containment ✔ Aggregation = Weak relationship ✔ Composition = Strong relationship ✔ Preferred over inheritance in many design cases 👉 Follow Ashok IT School for daily Java interview questions 👉 Comment “JAVA” for more concepts 👉For Java Course Details  Visit : https://lnkd.in/gwBnvJPR . #Java #CoreJava #OOPS #Aggregation #Composition #HASARelationship #JavaInterviewQuestions #AshokIT

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories