SCJP題庫第021題
1. 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.
Ans:B
解說:
go方法印出的squares是Batman的squares,incr所變更的squares是本身的方法變數
此是在考call by value觀念
Comments