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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "generics" Watch "generics" New topic
Author

generics

soujanya Bugatha
Greenhorn

Joined: May 29, 2012
Posts: 10
what is the output of this program?
import java.util.*;

class Empty {
}

class Extended extends Empty {
}

public class TryMe {
public static void doStuff1(List<Empty> list) {
// some code
}
public static void doStuff2(List list) {
// some code
}
public static void doStuff3(List<? extends Empty> list) {
// some code
}

public static void main(String args[]) {
List<Empty> list1 = new LinkedList<Empty>();
List<Extended> list2 = new LinkedList<Extended>();

// more code here
}
}

output is

A) doStuff1(list1);
B) doStuff2(list2);
C) doStuff2(list1);
D) doStuff3(list1);
E) doStuff3(list2);
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19064
    
  40

soujanya Bugatha wrote:
polymorphism doesn't apply for generic types right then how the answer 'D' is correct.


Saying that "the answer 'D' is correct" implies there is a question. In reading your post, I don't see the question.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: generics