File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Generics help explain 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 "Generics help explain" Watch "Generics help explain" New topic

Generics help explain

Pav Arora

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>(); 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: 2398
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

Joined: Dec 17, 2007
Posts: 28
Thanks guys.
I agree. Here's the link:
subject: Generics help explain
jQuery in Action, 3rd edition