Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


What is aggregation?



What is aggregation?..

Answer / bnaga

# Aggregation: If class have an entity reference,it is known as Aggregation. Aggregation represents HAS-A relationship.
Suppose.
Let suppose person have lots of information like name, address,phone number , id , education. so here we can further divide education in parts of education like
1)Post graduation
2)Graduation
3)Senior secondary
4)Higher secondary
in this case person have entity reference education

For example:

/*
class Person{
String name;
int id;
int Monumber;
String educatoin//entity refrence

}
*/

Why we use Aggregation : for code reusability in program.


By example :

Education.java
/*
public class Education {
String postgraduation,gradution,seniorsecondary,highersecondary;

public Education(String postgraduation,
String gradution,String seniorsecondary,String highersecondary) {

this.postgraduation = postgraduation;
this.gradution = gradution;
this.seniorsecondary = seniorsecondary;
this.highersecondary = highersecondary;
}

}

*/


Persona.java
/*
class Person{
String name;
int id;
Education edu; // entity reference

Person( String name, int id, Education edu){

this.name = name;
this.id = id;
this.edu = edu;
}

void showdata(){

System.out.println("Name:="+name+"Id:="+id);
System.out.println(edu.postgraduation+""+ edu.gradution+""+edu.seniorsecondary+""+edu.highersecondary)
}
public static void main(String args[]){
Education ed1 = new Education("MSC","BSC","10th","12th");
Education ed2 = new Education("MSC","BSC","10th","12th");

Person p1 = new Person("Bang",1,ed1);
Person p2 = new Person("Babu",2,ed2);

p1.showdata();
p2.showdata();

}
}
*/

Aggregatoin(HAS-A) is better than Composition(IS-A) relationship.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Core Java Interview Questions

What is comparator in java?

0 Answers  


Can a main method be overloaded?

0 Answers  


What are recursive functions?

0 Answers  


How do I remove a character from a string in java?

0 Answers  


What is use of valueof () in java?

0 Answers  


what is use of business objects?

3 Answers   Tech Mahindra,


Why are generics used?

0 Answers  


How many JVMs can run on a single machine and what is the Just-In-Time(JIT) compiler?

0 Answers   Global Logic,


int a=1; float b=1.0; System.out.println(a==b);

13 Answers   CTS, Honeywell, McAfee,


Describe the term diamond problem.

0 Answers  


Why java is considered dynamic?

0 Answers  


is memory to the abstract class allocated ..or objects not instantiated

7 Answers   Synechron, TCS,


Categories