Java Tut – Aggregation/HAS-A relationship


class Operation{
 int square(int n){
  return n*n;

class Circle{
 Operation 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[]){
   Circle c=new Circle();
   double result=c.area(5);


It would be a great help, if you support by sharing :)
Author: zakilive

Leave a Reply

Your email address will not be published. Required fields are marked *