| 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).
|
 |
 |
|
|
subject: kathy siera book self test question6 of generics
|
|
|