Aggregation is a special form of association. It is also a relationship between two classes like association, however its a directional association, which means it is strictly a one way association. It represents a Has-A relationship.
Aggregation is a relationship between two classes that
is best described as a "has-a" and "whole/part" relationship.
example:
imagine a Student class that stores information about
individual students at a school. Now let's say there is a Subject class that
holds the details about a particular subject (e.g., maths,history, geography).
If the Student class is defined to contain a Subject object then it can be said
that the Student object has-a Subject object. The Subject object also makes up
part-of the Student object, after all there is no student without a subject to
study. The Student object is therefore the owner of the Subject object.
public class Subject{ private String name; public void setName(String name) { this.name = name; } public String getName() { return name; } } public class Student { private Subject[] studyAreas = new Subject[10]; //the rest of the Student class }(); } } |
Core Java Interview Questions
Object Oriented Programming(OOP) Questions and Answers
Collections Interview Questions
Java Exceptions Interview Questions
Java Threads Interview Questions
Collection framework in java interview questions
oops concepts with example in java
Java Serialization Interview Questions
Top 20 Core Java Interview Questions with Answers
String Interview Question in java With Example
synchronization interview questions
Java Reflection Interview question
Java Executor Framework (JDK 1.5) Interview Questions
JDK 1.7 interview Questations and Answers
Java I/O interview question with example