File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question regarding Chapter 7 of K&B book Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Question regarding Chapter 7 of K&B book" Watch "Question regarding Chapter 7 of K&B book" New topic

Question regarding Chapter 7 of K&B book

Mark Gortzak

Joined: Dec 21, 2007
Posts: 1
I've been pouring over the answer (on page 628/629) to question 16 (on page 616/617). The last line reads "And D doesn't work, because in D we made Sheep extend Plant, not the Wolf class breaks because its munch(Sheep) method no longer fulfills the contract of Carnivore".

I can't figure out *why* D is wrong, or what they mean with that line. I asked some collegue's, but they can't figure it out either.
Hasnain Khan
Ranch Hand

Joined: Dec 15, 2007
Posts: 44
Hello Mark,

Guys correct me if im wrong.

Looking at the <Generic Type> in the interface definition,

interface Carnivore<E extends Animal> extends Hungry<E> {}

E is restricted to any type that is Either an Animal class itself or Subclasses of Animal.

Now since sheep extends Plant,

class Sheep extends Plant implements Carnivore<Wolf> {
public void munch(Wolf x) {}

replacing E with Sheep causes a compiler error because sheep is not an Animal anymore, its a Plant .

Hope that helped.
Kind Regards.
Hasnain Javed Khan.
I agree. Here's the link:
subject: Question regarding Chapter 7 of K&B book
It's not a secret anymore!