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
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply 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: 431


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: 280
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 Programmer
Arjun Srivastava
Ranch Hand

Joined: Jun 23, 2010
Posts: 431

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: 280
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://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: kathy siera book self test question6 of generics
 
Similar Threads
Diubt on Generics, Q.10 from K&b book
Generic Types extending Abstract implementing Interface
page# 616 question# 10
K&B -From genric & collections-Self Test
K&B collection and generic question