Professional Documents
Culture Documents
in Java
Note:
1. In the above example, there is a one to one relationship(Association)
between two classes: CarClass and Driver.
2. Both the classes represent two separate entities.
Note:
1. In above example two separate classes Bank and
Employee are associated through their Objects.
2. Bank can have many employees, So it is a one-to-
many relationship.
Operation
Square(int n);
Output:
78.5
Department of Computer Science 10
Aggregation Example 2
◼ In this example, Employee has an object of
Address, address object contains its own
information such as city, state, country etc.
❖ In such case relationship is Employee HAS-A
address.
//Address.java
//Emp.java
//AggregationTest.java
public class AggregationTest
{
public static void main(String[] args)
{
Address address1=new Address(“Abbottabad",“KPK",“Pakistan");
Address address2=new Address(“Haipur",“KPK",“Pakistan");
Emp e=new Emp(111,“Abdullah",address1);
Emp e2=new Emp(112,“KaleemUllah",address2);
e.display();
e2.display();
}
Output:
} 111 Abdullah
Abbottabad KPK Pakistan
112 KaleemUllah
Haripur KPK Pakistan