SCJP 1.6版考題 201

出自 陳富國維基館
前往: 導覽搜尋

SCJP201-1 2.png

Given:
1. import java.util.*;
2. class A{}
3. class B extends A{}
4. public class Test{
5.   public static void main(Strang[] args){
6.     List<A> listA = new LinkedList<A>();
7.     List listB = new LinkedList<B>();
8.     List<Obect> listO = new LinkedList<Obect>();
9.     //insert code here
10. }
11. public static void m1(List<? extends A> list){}
12. public static void m2(List<A> list){}
 
Place a result onto each method call to indicate 
what would happen if the method call were inserted at line 9. Note:  Results can be used more than once.


解答


Ans:
SCJP201-2.png

解說:

m1限定代入的參數是內存類別A或其子類別的串列集合 
m2限定代入內存類別A的串列集合
listA是內存類別A的集合
listB是內存類別B的集合
listO是內存類別O的集合