Java OCA OCP Practice Question 3225

Question

Which statements are true about the relationships between the following classes?

class Foo {/*  ww  w. j ava2 s.c om*/
  int num;
  Baz comp = new Baz();
}

class Bar {
  boolean flag;
}

class Baz extends Foo {
  Bar thing = new Bar();
  double limit;
}

Select the three correct answers.

(a) A Bar is a Baz.
(b) A Foo has a Bar.
(c) A Baz is a  Foo.
(d) A Foo is a Baz.
(e) A Baz has a Bar.


(b), (c), and (e)

Note

An instance of the class Baz is also an instance of the class Foo, since the class Baz extends the class Foo.

A Baz has a Bar since instances of the class Baz contain an instance of the class Bar by reference.

A Foo has a Baz, since instances of the class Foo contain an instance of the class Baz by reference.

Since a Foo has a Baz which has a Bar, a Foo has a Bar.




PreviousNext

Related