Java OCA OCP Practice Question 164

Question

Given:

3. public class Main { 
4.   static int myValue = 7; 
5.   public static void main(String[] args) { 
6.     new Main().go(myValue); 
7.     System.out.print(" " + myValue); 
8.   } /*from w  w  w  .  j a  v  a2 s . co  m*/
9.   void go(int myValue) { 
10.     myValue++; 
11.     for(int myValue = 3; myValue < 6; myValue++) 
12.       ; 
13.     System.out.print(" " + myValue); 
14.   } 
15. } 

What is the result?

  • A. 5 7
  • B. 5 8
  • C. 8 7
  • D. 8 8
  • E. Compilation fails
  • F. An exception is thrown at runtime


E is correct.

Note

The parameter declared on line 9 is valid.

The variable name myValue cannot be declared again on line 11 in the same scope as the declaration on line 9.




PreviousNext

Related