2009年2月17日 星期二

第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. 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.
答案:C
參考:9-7 測試程式與AssertionError錯誤事件

------------------------------------------------

第3行一值都是true,
第4行 assert 要為 false才會執行後面的程式碼.

沒有留言:

張貼留言