This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
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 Java 8 in Action this week in the Java 8 forum!
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: 18135

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)
It is sorta covered in the JavaRanch Style Guide.
subject: generics
Similar Threads
SCJP 6 question
Errors, Help on Jcreator?!
Linked List equals method
Generic Questions