Collections and Generics

© examsiri.com
Question : 12 of 53
 
Marks: +1, -0
Given:
Given:1. import java.util.*;
2. class A {}
3. class B extends A { }
4. public class Test {
5.   public static void main (String[ ] args) {
6.    List < A > listA = new LinkedList < A > ();
7.    List < B > listB = new LinkedList < B > ();
8.    List < Object > listO = new LinkedList < Object > ();
9.   /* insert code here*/
10 . }
11. public static void ml(List < ? extends A > list) { }
12. public static void m2(List < A > list) { }
13. }
Method calls Result
1. m1(listA); A) Does not compile
2. m1(listB); B) Compiles and runs without error
3. m1(listO); C) An exception is thrown at runtime
4. m2(listA);  
5. m2(listB);  
6. m2(listO);  
Go to Question: