Java Aggregation


In Java, the class has an entity reference which is called Aggregation.

It represents the HAS-A relationship.

It is used for code reusability.

Java Aggregation

Example:-

class Calculate
{  
    int rectangle(int n,int m)
    {  
        return n*m;  
    }  
}  
class A
{
    int rect;
    A(int length,int breadth)
    {   //aggregation
        Calculate ca; 
        ca=new Calculate();  
        rect=ca.rectangle(length,breadth);
        System.out.println("Area of Rectangle: "+rect);
    } 
}
public class Aggregation
{  
    public static void main(String args[])
    {  
        A c=new A(7,9); 
    }  
}   



OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.