Association in Java with Example

Price: INR 8,999.00
Price: INR 14,999.00
Was: INR 16,999.00

Association is the relationship between two objects. It is the important part of OOPs. In OOPS we can say, “If class A is in HAS-A relationship with Class B if class A holds the reference of class B“. This concept in OOPs is called association or Has-A relationship.

In such a way by having the reference of class B, class A can access the non-private properties of class B. Association is a relationship between two separate classes which can be of any type say one to one, one to may etc.

Association further divides into two types –

  • Aggregation

  • Composition

In Java inheritance is declared using the extends keyword. You declare that one class extends another class by using the extends keyword in the class definition.

Example – Employee and Teacher, where multiple employees can associate with the single organization and single employee can associate with multiple organizations. Both can be added and removed independently.

OutPut : Mirilla Knightly is an Employee of SeleniumBix


In the above example, one company has many numbers of Employees. Therefore company and Employee relationship are one to many. And also, those two are two different entities. Therefore the relationship between the two entities is called association.


Selenium Testing Video Tutorial:

If you liked this video, then please subscribe to our YouTube Channel for more video tutorials.

0 Comment

Leave a Reply