Professional Documents
Culture Documents
Topic 4 Part 2
Topic 4 Part 2
Topic 4 Part 2
OBJECT ORIENTED
PROGRAMMING
Topic 4:
Classes – Intermediate (Part 2)
TOPIC COVERED
Composite objects
Objects as parameter
“has-a” relation
.
.
.
}
EXAMPLE COMPOSITE CLASS 2
.
.
.
}
a) Example of normal constructor that has a composite object :
public Personal (int dDay, int dMonth, int dYear, String sName, int sId)
{
day = dDay;
month = dMonth;
year = dYear;
stu = new Student (sName, sId);
}
b) Example of mutator that has a composite object :
public void setPersonal (int dDay, int dMonth, int dYear, int sId, String sName)
{
day = dDay;
month = dMonth;
year = dYear;
stu.setStudent(sName, sId);
}
public void setPersonal (int dDay, int dMonth, int dYear, Student ss)
{
day = dDay;
month = dMonth;
year = dYear;
stu = ss;
}
SHARING AN OBJECT