Write a program in java to demonstrate aggregation?

class All

{

      int a;

      public All(int x)

      {

            a=x;

            System.out.println("In All");

      }

      public void display()

      {

            System.out.println(a);

      }

}

class Ball

{

      All on;

      int b;

      public Ball(int y)

      {

            b=10;

            on=new All(y);

      }

      public void display()

      {

            on.display();

            System.out.println(b);

      }

      public static void main(String arg[])

      {

            Ball x=new Ball(15);

            x.display();

      }

}

aggregation.PNG

, , , , ,

Leave a Reply