SCJP題庫第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.

Ans: C

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

Comments

Popular posts from this blog

Android+Google Map API v3 Geocoding(地址轉經緯度度