Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

generics

 
soujanya Bugatha
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21193
81
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic