"SCJP 1.6版考題 127" 修訂間的差異

出自 陳富國維基館
前往: 導覽搜尋
(新頁面: Given: 1. public class Donkey2{ 2. public static void main(Stnng[] args){ 3. boolean assertsOn = true; 4. assert(assertsOn): assertsOn = true; 5. if(assertsOn){ 6....)
 
(無差異)

於 2013年3月30日 (六) 03:55 的最新修訂

Given:
1. public class Donkey2{
2.   public static void main(Stnng[] args){
3.     boolean assertsOn = true;
4.     assert(assertsOn): assertsOn = true;
5.     if(assertsOn){
6.       System.out.println("assert is on");
7.     }
8.   }
9. }
 

If class Donkey2 is invoked twice,
the first time without assertions enabled,
and the second time with assertions enabled,
what are the results?
  A. no output
  B. no output assert is on
  C. assert is on
  D. no output , An Assertion Error is thrown.
  E. assert is on , An AssertionError is thrown.

解答


Ans: C

解說: 即使assert作用,4行也不會發生assertion error, assertOn是false才會發生assertion error