Java OCA OCP Practice Question 2372

Question

Assuming that the names of the classes used in the following code represent the actual objects, select the correct options.

class Shape {}
class Printable {}
class Sun { Shape rays; }
class Moon extends Printable {}
class Earth {}
class Main {
    Earth a;
    Moon b;
}
  • a Sun is associated with Shape.
  • b Moon is composed of Printable.
  • c Main is composed of Earth and Moon.
  • d Main is associated with Earth.
  • e Main is associated with Moon.
  • f Shape is composed of Sun.


a, c, d, e

Note

Option (a) is correct.

Sun gives out rays, so Sun is associated with Shape.

Option (b) is incorrect.

Moon is a type of Printable.

Composition is a whole-part relationship; if the enclosing object goes out of scope, the part also goes out of scope.

Option (c) is correct.

If Main goes out of scope, all the objects that it's composed of, including Earth and Moon, will go out of scope.

Options (d) and (e) are correct.

Composition is a special type of association, and objects in this relationship are associated with each other.

Option (f) is incorrect.

Shape isn't composed of Sun.

It's the other way around: Sun is composed of Shape.

If Sun goes out of scope, Shape also goes out of scope (is no longer visible).




PreviousNext

Related