OOP · OOP Relationships
Association
Imagine a college management system.
Real-World Problem
Imagine a college management system. A Student enrolls in a Course.
- A student can enroll in multiple courses.
- A course can have multiple students.
Even if a student leaves the college, the course still exists. Similarly, if a course is discontinued, the student still exists. Both objects are independent but connected.
This relationship is called Association What is Association? Association is an OOP relationship in which two or more independent objects interact with each other without owning one another. Each object has its own lifecycle and can exist independently. Association represents a uses or works with relationship.

Key Characteristics
- Objects are independent.
- No ownership exists.
- Both objects have separate lifecycles.
- Represents a Uses-A relationship.
Advantages
- Promotes loose coupling.
- Improves code flexibility.
- Encourages object collaboration.
- Easy to maintain and extend.
Diagram Explanation This diagram demonstrates Association using a real-world example.
- Rahul and Priya are two independent Student objects.
- Both students enroll in the Java Course.


A general "uses-a" link where two independent objects know about each other.
class Teacher {
String name;
Teacher(String name) { this.name = name; }
}
class Student {
String name;
Student(String name) { this.name = name; }
// Student is associated with a Teacher, but neither owns the other
void learnFrom(Teacher t) {
System.out.println(name + " learns from " + t.name);
}
}