File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
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
Author

Question regarding Chapter 7 of K&B book

Mark Gortzak
Greenhorn

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: http://aspose.com/file-tools
 
subject: Question regarding Chapter 7 of K&B book