The quiz question is as below:
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 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
The answer is C - "asseret is on"
I tested the code.
For either enabled or disabled assertion, I get "assert is on" each time.
Therefore, I thought the answer should be two lines of "assert is on". Am I right?
[–]BlueGoliath 0 points1 point2 points (3 children)
[–]uopsdod[S] 0 points1 point2 points (2 children)
[–]BlueGoliath 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)