Java OCA OCP Practice Question 2457

Question

Given:

2. import java.util.*;  
3. class Shape { }  
4. public class Square extends Shape {  
5.   public static void main(String[] args) {  
6.     List<Square> c0 = new List<Square>();  
7.     List<Shape> c1 = new ArrayList<Shape>();  
8.     List<Shape> c2 = new ArrayList<Square>();  
9.     List<Square> c3 = new ArrayList<Shape>();  
10.     List<Object> c4 = new ArrayList<Square>();  
11.     ArrayList<Shape> c5 = new ArrayList<Square>();  
12.   }  //from   w ww.j a va 2  s  . c om
13. } 

Which are true? (Choose all that apply.)

  • A. Compilation succeeds.
  • B. Compilation fails due to an error on line 6.
  • C. Compilation fails due to an error on line 7.
  • D. Compilation fails due to an error on line 8.
  • E. Compilation fails due to an error on line 9.
  • F. Compilation fails due to an error on line 10.
  • G. Compilation fails due to an error on line 11.


B, D, E, F, and G are correct

Note

B, D, E, F, and G are correct because those lines of code will NOT compile.

B, (line 6), is incorrect because List is abstract.

D, E, F, and G are all incorrect because polymorphic assignments can't be applied to the generic type parameter.

C is incorrect because line 7 uses legal syntax.




PreviousNext

Related