Free Practice Quiz Question List

7 Composition and Object Collaboration Online Quiz Questions

Use this free practice quiz with 20 questions to review 7 Composition and Object Collaboration, test your knowledge, and prepare for your next test or exam.

20 questions
01
True or false
1 point

True or false: In object-oriented design, composition represents a has-a relationship between an object and the objects it uses as parts or collaborators.

  1. A

    True

  2. B

    False

02
Choose one
1 point

Which example best illustrates delegation?

  1. A

    A Document implements every formatting algorithm inside its publish method.

  2. B

    A Document calls its Formatter's format method to format text.

  3. C

    A Document exposes its Formatter's internal fields to callers.

  4. D

    A Document subclasses Formatter to inherit formatting behavior.

03
Written response
1 point

A class named Car stores an Engine object and uses it to provide part of the car's behavior. What relationship does this design express?

04
Fill in the blank
1 point

When an object receives a request and passes responsibility for part of that request to a collaborator, this is called .

05
Choose one
1 point

In the statement class SavingsAccount extends BankAccount, what relationship is the design primarily expressing?

  1. A

    A SavingsAccount has an unrelated BankAccount.

  2. B

    A SavingsAccount delegates all work to a BankAccount.

  3. C

    A SavingsAccount is a BankAccount.

  4. D

    A SavingsAccount is a component inside a BankAccount.

06
Fill in the blank
1 point

A well-designed collaborator should have a clear and be accessed through a small, stable .

07
Choose all
1 point

Which three are advantages of composition described in the material? Select all correct choices.

  1. A

    Lower coupling to implementation details

  2. B

    Independent variation of behavior

  3. C

    A fixed implementation determined by the object's class

  4. D

    Replacing an external service with a test implementation

08
True or false
1 point

True or false: In Java, unrelated classes can implement the same interface and be used through that common interface type.

  1. A

    True

  2. B

    False

09
Written response
1 point

In the CheckoutService example, what collaborator type supplies the payment operation that checkout invokes?

10
Choose one
1 point

A payroll system must switch among hourly, salaried, overtime, and promotional pay rules without changing the Employee class. Which design best applies composition?

  1. A

    Make every pay rule a subclass of Employee and remove the policy object.

  2. B

    Store a PayPolicy in Employee and delegate calculatePay to that policy.

  3. C

    Make Employee extend PayPolicy because it calculates pay.

  4. D

    Put all hourly, salaried, overtime, and promotional rules directly into one fixed Employee class.

11
Choose all
1 point

Which three situations specifically suggest choosing composition instead of inheritance? Select all correct choices.

  1. A

    The relationship is not genuinely is-a.

  2. B

    Behavior needs to vary independently of the object's identity.

  3. C

    Closely related classes need shared protected state and concrete implementation.

  4. D

    Several independent features would otherwise require many subclasses.

12
Open ended
1 point

Explain how composition and inheritance differ in the relationships they model, and describe when composition is preferable and when inheritance remains appropriate. Use the material's design criteria rather than simply saying that one technique is always better.

13
Choose one
1 point

According to the design guidance, what is a warning sign that delegation has become ineffective?

  1. A

    It always makes a class larger.

  2. B

    It prevents interfaces from being used.

  3. C

    It consists of pointless forwarding that may hide an unclear responsibility boundary.

  4. D

    It requires every collaborator to be a superclass.

14
True or false
1 point

True or false: A class using composition should generally keep its collaborators private and expose a focused public interface.

  1. A

    True

  2. B

    False

15
Choose one
1 point

A system must select different delivery behaviors according to deployment configuration, while keeping the main service class unchanged. Which design best uses composition?

  1. A

    Create a subclass for every possible configuration

  2. B

    Hard-code one collaborator inside the class

  3. C

    Supply the collaborator through a constructor or setter

  4. D

    Put all alternative behaviors into one large method

16
Choose one
1 point

Which statement best describes the goal of object collaboration?

  1. A

    It eliminates all relationships among objects

  2. B

    It makes relationships explicit, small, and understandable

  3. C

    It requires every object to perform the whole task itself

  4. D

    It replaces interfaces with shared mutable data

17
Choose one
1 point

A company expects to add hourly, salaried, overtime, and promotional pay rules independently of an employee's identity. Which design best reflects the material?

  1. A

    Make every pay policy a superclass of Employee

  2. B

    Store all pay algorithms directly in Employee

  3. C

    Give Employee a PayPolicy collaborator

  4. D

    Make Employee extend each pay-policy class

18
Choose one
1 point

In the example with Document and Formatter, which interaction is delegation?

  1. A

    Document calls Formatter.format(text) to perform the formatting

  2. B

    Formatter calls Document.publish(text) to perform the formatting

  3. C

    Document copies the formatter's internal state into its own fields

  4. D

    Document subclasses every formatter implementation

19
Written response
1 point

What relationship does composition represent between a containing object and one of its components?

20
Written response
1 point

What design term describes an object receiving a request and passing responsibility for part of it to a collaborator?