aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Collections with hierarchical type parameter 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 "Collections with hierarchical type parameter" Watch "Collections with hierarchical type parameter" New topic
Author

Collections with hierarchical type parameter

timo corn
Ranch Hand

Joined: Oct 26, 2013
Posts: 68



Is the following correct:
-Grass and Plant have nothing to do here
-Sheep is a animal and eats plants (why is there "<sheep>" as Herbivore type?). Sheep eat sheep?
-Wolf is a animal and eats meat (sheeps)
-Interfaces Carnivores and Herbivores are of type hungry, so they are hungry


hth
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18988
    
  40


Please QuoteYourSources.


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Himai Minh
Ranch Hand

Joined: Jul 29, 2012
Posts: 798
    
    1


Is the following correct:
-Grass and Plant have nothing to do here
-Sheep is a animal and eats plants (why is there "<sheep>" as Herbivore type?). Sheep eat sheep?
-Wolf is a animal and eats meat (sheeps)
-Interfaces Carnivores and Herbivores are of type hungry, so they are hungry

I know this is from the self-test in KB's book.
What is your question regarding to this self test question? If you don't understand the explanation in the self-test, let us know.

Why is there <Sheep> as Herbivore type?

Herbivore <E extends Animal> means Herbivore take an Animal as its generic parameter. Sheep is an animal. So, Herbivore<Sheep> compiles.

timo corn
Ranch Hand

Joined: Oct 26, 2013
Posts: 68

So is sheep an animal that eats plants and wolf an animal that eats meat? Normally, classes and interfaces do not make sense in the ocjp, but I think in this example you HAVE to understand the class behaviour? Am I right?

I do not understand the implementations Carnivore<sheep> and Herbivore<Sheep>. Should be Carnivore<an aggressive animal like a wolf>?

Henry, the example is taken from kb, self test, chapter collections.
 
wood burning stoves
 
subject: Collections with hierarchical type parameter