Java Program using aggregation


In this program, You will learn how to implement aggregation in java.


Aggregation in Java represents HAS-A relationship. "Alternative of Inheritance."

Example: How to implement aggregation in java.

class Abc {
    int x = 10;
}

class Main {

    Abc obj;

    void display() {
        obj = new Abc();
        System.out.println("The x value is:" + obj.x);
    }

    public static void main(String args[]) {
        Main t = new Main();
        t.display();
    }
}

Output:

The x value is:10