SCJP 1.6版考題 030

出自 陳富國維基館
前往: 導覽搜尋
1. public class SimpleCalc{
2.   public int value;
3.   public void calculate(){value += 7;}
4. }
And:
1. public class MultiCalc extends SimpleCalc{
2.   public void calculate(){value -= 3;}
3.   public void calculate(int multiplier){
4.     calculate();
5.     super.calculate();
6.     value *= multiplier;
7.   }
8.   public static void main(String[] args){
9.     MultiCalc calculator = new MultiCalc();
10.    calculator.calculate(2);
11.    System.out.println("Value is: " + calculator.value);
12.   }
13. } 


What is the result?
  A. Value is: 8
  B. Compilation fails.
  C. Value is: 12
  D. Value is: -12
  E. The code runs with no output.
  F. An exception is thrown at runtime. 

解答


Ans: A

解說: 無