aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes kathy siera book self test question6 of generics Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "kathy siera book self test question6 of generics" Watch "kathy siera book self test question6 of generics" New topic
Author

kathy siera book self test question6 of generics

Arjun Srivastava
Ranch Hand

Joined: Jun 23, 2010
Posts: 432


what changes would allow this code to compile?
B change herbivore to
C change sheep class to

D
E change wolf class to


Answer is B given in book.

yes it is right, i agree, B is correct and C is wrong.

but if i try D and E also instead of B, the code also compiled successfully.


SCJP 6 | FB : Java Certifications-Help. | India Against Corruption
Dieter Quickfend
Ranch Hand

Joined: Aug 06, 2010
Posts: 359
You should read the book better. The code snippet you gave for D is not consistent with that in the book. In the book, sheep extends Plant, which solves sheep's problem, but doesn't compile because it breaks wolf's contract (carnivore)

and E will only compile if the class already compiles. It doesn't solve any problem with sheep.


Oracle Certified Professional: Java SE 6 Programmer
Oracle Certified Expert: Java EE 6 Web Component Developer
Oracle Certified Expert: Java EE 6 Enterprise JavaBeans Developer
Arjun Srivastava
Ranch Hand

Joined: Jun 23, 2010
Posts: 432

Dieter Quickfend wrote:In the book, sheep extends Plant, which solves sheep's problem, but doesn't compile because it breaks wolf's contract (carnivore)

hi thanks, i have edited my post.
i get through with E fine.ok

when i use D, i get
type parameter sheep is not within its bound

how sheep breaks wolf contract please elaborate if you can.
Dieter Quickfend
Ranch Hand

Joined: Aug 06, 2010
Posts: 359
Wolf is a Carnivore and eats Sheep.
If Sheep IS-A plant, Wolf must be a Herbivore, because Sheep is no longer an Animal (it IS-A Plant).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: kathy siera book self test question6 of generics
 
Similar Threads
Diubt on Generics, Q.10 from K&b book
page# 616 question# 10
K&B collection and generic question
K&B -From genric & collections-Self Test
Generic Types extending Abstract implementing Interface