aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Generics Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Generics" Watch "Generics" New topic
Author

Generics

kathir vel
Ranch Hand

Joined: Jul 03, 2007
Posts: 92
Hi All,

I thought the answer is all options.But exam shows only A,E,F.Can anyone clarify this pgm?Adavance Thanks.



1. import java.util.*;
2. public class Fruits {
3. public static void main(String [] args) {
4. Set c1 = new TreeSet();
5. Set o1 = new TreeSet();
6. bite(c1);
7. bite(o1);
8. }
9. // insert code here
10. }
11. class Citrus { }
class Orange extends Citrus { }

Which, inserted independently at line 9, will compile? (Choose all that apply.)

A). public static void bite(Set<?> s) { }
B). public static void bite(Set<Object> s) { }
C). public static void bite(Set<Citrus> s) { }
D). public static void bite(Set<? super Citrus> s) { }
E). public static void bite(Set<? super Orange> s) { }
F). public static void bite(Set<? extends Citrus> s) { }
G). Because of other errors in the code, none of these will compile.
Manfred Klug
Ranch Hand

Joined: Jun 04, 2007
Posts: 377
Originally posted by kathir vel:
I thought the answer is all options.But exam shows only A,E,F.Can anyone clarify this pgm?
You are correct. Since o1 and c1 have no element type information, the compiler assumes that the programmer knows what he does, and issues only a warning (except for case A, where any list is valid).
kathir vel
Ranch Hand

Joined: Jul 03, 2007
Posts: 92
Thank you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Generics