0% found this document useful (0 votes)
15 views1 page

Understanding Aggregation in Java

The document discusses aggregation in Java which is a type of HAS-A relationship where one object contains a reference to another object. Aggregation represents a relationship where two objects can exist independently and if one is deleted the other can still exist. An example is given of a room containing a chair object to demonstrate aggregation.

Uploaded by

shoth456
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views1 page

Understanding Aggregation in Java

The document discusses aggregation in Java which is a type of HAS-A relationship where one object contains a reference to another object. Aggregation represents a relationship where two objects can exist independently and if one is deleted the other can still exist. An example is given of a room containing a chair object to demonstrate aggregation.

Uploaded by

shoth456
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

[Link] By Mr.

Vishnu

Aggregation in java
Aggregation is a type of HAS-A relationship. Aggregation represents a type of
relationship between two objects in which one contain the other’s reference. Two
objects can exist independently. If one is deleted other can still exist.

Aggregation in real world:

Let us take the example: A room has a chair. Here room object contain the chair object.
Both room and chair exist independently.

Example:

package [Link];

//This is used to show simple aggregation example.


class Chair{
public void show(){
[Link]("show chair details.");
}
}

public class Test{


public static void main(String args[]){
//Chair class object in RoomTest class
Chair obj = new Chair();
[Link]();
}

Output:

show chair details.

Note: Aggregation is mainly used for code re-usability.

1
Sri Sureka Technologies, NearAndraBank,Opposite Geethanjali High School, Near [Link]
UmeshChandraStachu, [Link], Hyderabad-500038, Ph: 040-66616677, Mobile: +91-9885602332.

You might also like