If class Donkey is invoked twice, the first time without assertions enabled, and the second time with assertions enabled, what are the results?

Given:

public class Donkey2 {
public static void main(String[] args) {
boolean assertsOn = true;
assert (assertsOn) : assertsOn = true;
if(assertsOn) {
System.out.println(“assert is on”);
}
}
}

If class Donkey is invoked twice, the first time without assertions enabled, and the second time with assertions enabled, what are the results?

Given:

public class Donkey2 {
public static void main(String[] args) {
boolean assertsOn = true;
assert (assertsOn) : assertsOn = true;
if(assertsOn) {
System.out.println(“assert is on”);
}
}
}

If class Donkey 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 AssertionError is thrown.

E.
assert is on
An AssertionError is thrown.

Explanation:



Leave a Reply 1

Your email address will not be published. Required fields are marked *


MockdanJung

MockdanJung

I expected answer will be ‘assert is on assert is on’. but answer is C.
I don’t understand it.
is anybody can explain the reason?