.


Divya

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

Syntax:

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

Example

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);
System.out.println(result);
}
}

Output :
92.5



.