TODAY JAVA SCHOOL

In java school, programming, design, computer general knowledge, web application, software, web services, social media, digital marketing, oops, concept of programming language, oops feature, console media, graphics medium, first programming, c, c ++ , Java, PHP, SQL, MySQL, HTML, HTML_5, J_query, JavaScript, Bootstrap, Framework, images with logos, examples, shared and explained.

https://www.amazon.in/b?node=26373545031&linkCode=ll2&tag=1234567801cdb-21&linkId=3b9882431b00409b44141e0344b35a15&language=en_IN&ref_=as_li_ss_tl

Breaking

Sunday, 12 April 2020

Aggregation In Java | Aggregation In Java Program | Aggregation In Java In Hindi

                                Aggregation in Java

If a class have an entity reference, it is known as Aggregation. Aggregation represents HAS-A relationship.
Employee object contains many informations such as id, name, emailId etc. It contains one more object named address, which contains its own informations such as city, state, country, zipcode etc.

As given below

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


Simple Example of Aggregation 

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

Output:

78.5

aggregation in java example


Fig: Aggregation In Java 



}  

No comments:

Post a Comment