Core Java SQL Oracle PHP Examples JSP JDBC MORE

Java aggrigation

Without existing container object if there is a chance of existing contained object then container and container object are weekely associated and this week association is nothing but aggregation

In aggregation container object holds just references of contained object


class Student{
int id;
String name;
Address address;//Address is a class


class Mathematical calculation{
int cube(int a){
return a*a*a;
class Triangle{
Mathematical calculation op;//aggregation
double pi=3.14;
double area(int radius){
op=new Operation();
int rsquare=op.square(radius);//code reusability (i.e. delegates the method call).
return pi*rsquare;
public static void main(String args[]){
Triangle c=new Triangle();
double result=c.area(5);

Output :