Preview

09 - Aggregation

 1. Composition is a way of aggregating ___________________ by making some objects attributes of other objects

  objects together

  methods together

  values together

  classes and attributes together

 2. Association aggregaion is where an object that is created can contain other objects and if ___________________

  the original object is deleted, the composed objects will all also be deleted

  the original object is deleted, then the composed objects will continue to exist

  the original object is deleted, the composed objects will be duplicated

  None of the above

 3. Composition aggregation is where an object that is created can be composed of the other objects; if the original object is deleted then……

  the original object is deleted, then the composed objects will continue to exist

  the original object is deleted, the composed objects will all also be deleted

  the original object is deleted, the composed objects will be duplicated

  None of the above

 4. It is possible, for example, to make a datetime.date object an attribute of a Person object, and use it to store a person’s birthdate

  TRUE

  FALSE

 5. An aggregate object is one which _____________-

  inherits from an object or at least two classes

  contains other objects

  contains a class reference

  does not contain other objects

 6. Aggregation provides an easy way for two objects to know about each other (and hence message each other).

  FALSE

  TRUE

 7. An association is a "using" relationship between two or more objects in which the objects have their own life time and there is no owner
A doctor can be associated with multiple patients and at the same time, 
one patient can visit multiple doctors for treatment and/or consultation. 
Each of these objects have their own life-cycle and there is no owner.

  FALSE

  TRUE

 8. Aggregation like association can be used to represent a one-to-many or many-to-many relationship between the participating objects due to which we may say that it is a redundant relationship.

  FALSE

  TRUE

 9. What does the following example (in Java) demonstrate?
class Address
{
   int streetNum;
   String city;
   String state;
   String country;
   Address(int street, String c, String st, String coun)
   {
       this.streetNum=street;
       this.city =c;
       this.state = st;
       this.country = coun;
   }
}
class StudentClass
{
   int rollNum;
   String studentName;
   //Creating HAS-A relationship with Address class
   Address studentAddr; 
   StudentClass(int roll, String name, Address addr){
       this.rollNum=roll;
       this.studentName=name;
       this.studentAddr = addr;
   }
   public static void main(String args[]){
       Address ad = new Address(55, "Oxford Circus", "London", "United Kingdom");
       StudentClass obj = new StudentClass(123, "Ruth Marvin", ad);
       System.out.println(obj.rollNum);
       System.out.println(obj.studentName);
       System.out.println(obj.studentAddr.streetNum);
       System.out.println(obj.studentAddr.city);
       System.out.println(obj.studentAddr.state);
       System.out.println(obj.studentAddr.country);
   }
}

  Aggregation between the two objects 'Name' and 'Address'

  None of the above

  Aggregation between Student and Address classes.(A property of type Address has been declared to obtain student address in the Student Class)

  Aggregation within the Address class

 10. Why do we need Aggregation?

  None of the above

  to maintain the structural precision of the program

  to maintain code re-usability

  to maintain the ability to delete a class when necessary