Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Generics ques...pl help explain

 
Pav Arora
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic