Java OCA OCP Practice Question 172

Question

Given:

public class Main { 
  static int myField = 2; 
  public static void main(String[] args) { 
    go(); //from   w  w w  .java 2  s .c  o m
  } 
  static void go() { 
    int myField = 3; 
    zoomIn(); 
  } 
  static void zoomIn() { 
    myField *= 5; 
    zoomMore(myField); 
    System.out.println(myField); 
  } 
  static void zoomMore(int myField) { 
    myField *= 7; 
  } 
} 

What is the result?

  • A. 2
  • B. 10
  • C. 15
  • D. 30
  • E. 70
  • F. 105
  • G. Compilation fails


B is correct.

Note

In the Main class, there are three different variables named myField.

The go() method's version and the zoomMore() method's version are not used in the zoomIn() method.

The zoomIn() method multiplies the class variable * 5.

The result (10) is sent to zoomMore(), but what happens in zoomMore() stays in zoomMore().

The S.O.P. prints the value of zoomIn()'s myField.




PreviousNext

Related