- Given: 1. class Zing { 2. protected Hmpf h; 3. } 4. class Woop extends Zing { } 5. class Hmpf { } Which is true? (Choose all that apply.)
-
Woop is-a Hmpf and has-a zing.
-
zing is-a Woop and has-a Hmpf.
-
Hmpf has-a Woop and Woop is-a Zing.
-
Woop has-a Hmpf and Woop is-a zing.
-
Zing has-a Hmpf and Zing is-a Woop.
Woop extends Zing, so Woop IS-A Zing (not the reverse). Zing has a protected Hmpf field, so Woop inherits it - thus Woop HAS-A Hmpf. Option D is correct: Woop has-a Hmpf (through inheritance) and Woop is-a Zing (extends). Other options reverse relationships or claim incorrect associations.
To answer this question, let's go through each option:
Option A) Woop is-a Hmpf and has-a zing. This option is incorrect because Woop is not a Hmpf and there is no mention of a zing in the given code.
Option B) zing is-a Woop and has-a Hmpf. This option is incorrect because zing is not a Woop and there is no mention of a Hmpf in the given code.
Option C) Hmpf has-a Woop and Woop is-a Zing. This option is incorrect because Hmpf does not have a Woop and Woop is not a Zing.
Option D) Woop has-a Hmpf and Woop is-a zing. This option is correct because Woop does have a Hmpf (as inherited from the parent class Zing) and Woop is not a zing (case-sensitive error).
Option E) Zing has-a Hmpf and Zing is-a Woop. This option is incorrect because Zing does not have a Hmpf and Zing is not a Woop.
The correct answer is D. Woop has-a Hmpf and Woop is-a zing.