SCJP 1.6版考題 127

出自 陳富國維基館
於 2013年3月30日 (六) 03:55 由 Ikk (對話 | 貢獻) 所做的修訂 (新頁面: 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....)
(差異) ←上個修訂 | 最新修訂 (差異) | 下個修訂→ (差異)
前往: 導覽搜尋
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