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 |
How to check if linked list contains loop in java?
Explain Global variables in Packages?
What is jar?
What is meant by Session? Explain something about HTTP Session Class?
What is a nullable field?
What is supplier in java?
What is the final field modifier?
what is function overloading in java?
0 Answers Tavant Technologies, TCS, Virtusa,
How to sort elements in a parallel array in java?
How does compareto method work?
What are the supported platforms by java programming language?
public class AboutStrings{ public static void main(String args[]){ String s1="hello"; String s2="hel"; String s3="lo"; String s4=s2+s3; //to know the hash codes of s1,s4. System.out.println(s1.hashCode()); System.out.println(s4.hashCode()); // these two s1 and s4 are having same hashcodes. if(s1==s4){ System.out.println("s1 and s4 are same."); }else System.out.println("s1 and s4 are not same."); } } Somebody told me that, == operator compares references of the objects. In the above example even though s1 and s4 are refering to same object(having same hash codes), it is printing s1 and s4 are not same. Can anybody explain in detail why it is behaving like this? Thanks in Advance RavuriVinod