• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Why the answer is... MasterExam

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OBJECTIVE: Write Generic Methods (Objective 6.4)

class Food { }
class Fruit extends Food { }
class Apple extends Fruit { }
// insert code here
public static void main(String[] munch) {
Pie<Fruit> p = new Pie<Fruit>();
}
}

Which inserted at // insert code here, will compile? (Choose all that apply.)

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>{

-------------------
correct answer is:A, B, and F are correct. C and D are incorrect because Fruit is not "in bounds" as a type of Apple or Pie when you try to instantiate a new Pie. E is incorrect syntax.

---------------------------
my answer is: A,E,F

Why E is incorrect?


Thanks
[ August 29, 2008: Message edited by: Samson Harry ]
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Samson, welcome to JavaRanch.

One of the rules of the JavaRanch SCJP forum is that if you copy a question from a book or mock exam, you are required to quote your sources. So please tell us where you copied this question from.
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well I think that super can be used only with ? like <? super Apple> in method calls.....

I think I am correct as I am not very comfortable with generics.....
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic