• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

one mock exam question from K&B book

 
Phone Myat Kyaw
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I'm going to sit the SCJP 6.0 exam tomorrow and I'm doing my final preparation. Here's one question make me confusing.

1. class Zing {
2. Hmpf h;
3. }
4. class Woop extends Zing{}
5. class Hmpf { Zing z; }
Which is true? (Choose all that apply.)

Answers are
Zing has-a Hmpf and Woop is-a Zing.
Hmpf has-a Zing and Woop has-a Hmpf.

I completely understand the first one - Zing class has a Hmpf ref while Woop is inherited from Zing.
But I don't understand why the second answer is correct. What I see is, the first part, Hmpf has-a Zing, is true
but the latter is not. But the mock test I'm taking (from the K&B book) give both are correct.

Can someone explain me in a bit more detail?
thanks
 
Phone Myat Kyaw
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh nvm, just my stupid careless mistake.

Because of inheritance, Woop also has Hmpf.

Sorry for my post(happened to be spam)
 
Lucas Smith
Ranch Hand
Posts: 808
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Phone Myat Kyaw wrote:Hi, I'm going to sit the SCJP 6.0 exam tomorrow and I'm doing my final preparation. Here's one question make me confusing.

1. class Zing {
2. Hmpf h;
3. }
4. class Woop extends Zing{}
5. class Hmpf { Zing z; }
Which is true? (Choose all that apply.)

Answers are
Zing has-a Hmpf and Woop is-a Zing.
Hmpf has-a Zing and Woop has-a Hmpf.

I completely understand the first one - Zing class has a Hmpf ref while Woop is inherited from Zing.
But I don't understand why the second answer is correct. What I see is, the first part, Hmpf has-a Zing, is true
but the latter is not. But the mock test I'm taking (from the K&B book) give both are correct.

Can someone explain me in a bit more detail?
thanks


Whoop HAS-A Hmpf brcause it's inherited from Zing.

Just have a look:
 
Phone Myat Kyaw
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks alot Lukas
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic