Section 8.7: Aggregation

Ace your homework & exams now with Quizwiz!

Assume that you have written a copy constructor for the CourseMode class to avoid a security hole. Write a statement that creates a new CourseMode object called courseMode for a Course instance by calling the copy constructor, with mode as a parameter.

CourseMode courseMode = new CourseMode(mode);

We'll work some more with the CourseMode class in the next three exercises.To avoid null references to CourseMode objects, write a no-argument constructor that assigns an empty string to its member variable, mode.

CourseMode() {mode = new String("");}

When do you perform deep copies?

When creating field objects. When you make a copy of the aggregate object, you must be sure to copy the make copies of the objects it references.

When making copies of aggregate objects, it's best practice to make ____ its field objects.

deep copies

You show aggregation in a UML diagram by connecting two classes with a line that has a(n) _______ at the end that is closest to the _______.

diamond; aggregate

Creating multiple instances of a field within a single class is known as aggregation.

false

With aggregation, a(n) _______ relationship exists between classes.

has a

It is not recommended to write a method that returns a reference to an object that is a ______ field within a class unless that object is a(n) _______.

private; String

getCourseMode method shown below returns a copy of the current Course object's mode in one return statement. What is the return statment?public CourseMode getCourseMode(){// Return a copy of the mode object.}

return new CourseMode(mode);


Related study sets

Mortgage Loan Origination Activities 25%

View Set

Data Structure and Algorithm patterns

View Set

Unit 3: The Effect of Natural Forces on your Vehicle

View Set

Lesson 1 grammar on imperfect (fill in the blanks)

View Set

Intermediate Financial Accounting Exam 2

View Set