| Author |
Generics ques...pl help explain
|
Pav Arora
Greenhorn
Joined: Dec 17, 2007
Posts: 28
|
|
When I went thru KB, I thought I have understood Generics. I am not getting the following question - Which inserted at // will compile a) class Pie<T extends Food> { b) class Pie<T extends Fruit> { c) class Pie<T extends Apple> { d) class Pie<T extends Pie> { e) class Pie<T super Apple> { f) class Pie<T>{
|
 |
sree visu
Ranch Hand
Joined: Jul 05, 2007
Posts: 133
|
|
|
i am not sure about the answer but i hope "B" is the correct answer .this is because Pie<Fruit> p=new pie<fruit>(); ..so here anything that the class can take must be that extends fruit.
|
Regards<br />Sree Visu<br />SCJP 5.0, SCWCD 5.0, SCJD(Preparing B&S 2.2.2)
|
 |
Keith Lynn
Ranch Hand
Joined: Feb 07, 2005
Posts: 2341
|
|
a, b, and f should work Apple is a subclass of Fruit so c won't work. Pie has no relation to Fruit so d won't work. super isn't used in a generic class definition so e won't work.
|
 |
Pav Arora
Greenhorn
Joined: Dec 17, 2007
Posts: 28
|
|
|
Thanks guys.
|
 |
 |
|
|
subject: Generics ques...pl help explain
|
|
|