자격증/OCJP_ExamA

QUESTION 47

IT grow. 2018. 7. 8. 19:00
반응형

QUESTION 47 


Given: 

 

1. public class Batman { 

2.     int squares = 81; 

3.     public static void main(String[] args) { 

4.         new Batman().go(); 

5.     } 

6.     void go() { 

7.         incr(++squares); 

8.         System.out.println(squares); 

9.     } 

10.     void incr(int squares) { squares += 10; } 

11. } 

 

What is the result? 

 

A. 81 

B. 82 

C. 91 

D. 92 

E. Compilation fails. 

F. An exception is thrown at runtime


Solution : B 


Plus imformation : 


정사각형은 81로 시작합니다.

square 값은 incr 메소드 (82)에 입력하기 전에 증가됩니다.

inside incr 메서드에서 다른 사각형을 10 씩 증가시킵니다 (섀도 잉).

incr 메서드가 종료되면 클래스 변수 사각형이 82로 계속됩니다.


반응형