Java OCA OCP Practice Question 2570

Question

Given:

2. public class Main {  
3.   Main v;  /*from   w  w  w . ja  v  a 2  s . c o  m*/
4.   int size;  
5.   public static void main(String[] args) {  
6.     Main myV = new Main();  
7.     final Main v2;  
8.     v2 = myV.doStuff(myV);  
9.     v2.v.size = 7;   
10.     System.out.print(v2.size);  
11.   }  
12.   Main doStuff(Main v3) {  
13.     v3.size = 5;  
14.     v3.v = new Main();  
15.     return v3;  
16. } } 

What is the result? (Choose all that apply.)

  • A. 5
  • B. 7
  • C. Compilation fails due to an error on line 8.
  • D. Compilation fails due to an error on line 9.
  • E. Compilation fails due to an error on line 13.
  • F. Compilation fails due to an error on line 14.


A is correct.

Note

A reference variable marked "final" cannot reference a different object, but the object it references can be changed.




PreviousNext

Related