nerdexam
Oracle

1Z0-804 · Question #24

Which is a key aspect of composition?

The correct answer is B. Method delegation. In the composition approach, the subclass becomes the "front-end class," and the superclass becomes the"back-end class." With inheritance, a subclass automatically inherits an implemenation of any non-privatesuperclass method that it doesn't override. With composition, by…

Object-Oriented Design Principles

Question

Which is a key aspect of composition?

Options

  • AUsing inheritance
  • BMethod delegation
  • CCreating abstract classes
  • DImplementing the composite interface

How the community answered

(18 responses)
  • A
    6% (1)
  • B
    78% (14)
  • C
    6% (1)
  • D
    11% (2)

Explanation

In the composition approach, the subclass becomes the "front-end class," and the superclass becomes the"back-end class." With inheritance, a subclass automatically inherits an implemenation of any non-privatesuperclass method that it doesn't override. With composition, by contrast, the front-end class must explicitlyinvoke a corresponding method in the back-end class from its own implementation of the method. This explicitcall is sometimes called "forwarding" or "delegating" the method invocation to the back-end object. Note: Composition means the same as: Note 2: As you progress in an object-oriented design, you will likely encounter objects in the problem domainthat contain other objects. In this situation you will be drawn to modeling a similar arrangement in the design ofyour solution. In an object-oriented design of a Java program, the way in which you model objects that containother objects is with composition, the act of composing a class out of references to other objects. Withcomposition, references to the constituent objects become fields of the containing object. To use compositionin Java, you use instance variables of one object to hold references to other

Topics

#composition#method delegation#design patterns#object relationships

Community Discussion

No community discussion yet for this question.

Full 1Z0-804 Practice