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


soujanya Bugatha

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

Joined: Sep 28, 2004
Posts: 20524

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.


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
I agree. Here's the link:
subject: generics
jQuery in Action, 3rd edition