Java problem Give a UML example illustrating aggregation Inc
Solution
Aggregation is a connection between two classes that is best described as a \"has-a\" and \"entire/part\" connection Let Subject be the super class and Student, Instructor be the two sub classes .
This is an example of aggregation because student has a subject and Instructor has a subject (i,e has a relationship holds)
For example, imagine a Student class that stores information regarding individual students at a school.
Now let\'s say there is a Subject class that holds the information about a particular subject (e.g., history, geography).
If the Student class is defined to have 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 with no subject to study.
The Student object is therefore the holder of the Subject object.
Similarly for instructor
Code:
public class Subject {
private String name;
public void setName
(String name)
{ this.name = name;
}
public String getName() {
return name;
}
}
public class Student {
private String id;
private String name;
private float cg;
public void setCg(float cg) { this.cg = cg; }
public String getCg() { return cg; }
}
public class Student {
private String InstrId;
private String name;
private int age;
public void setAge(int age) { this.age = age; }
public String getAge() { return age; } }

