Java SE 8 Programmer II — Question 157
Given:
public class Counter {
public static void main (String[ ] args) {
int a = 10;
int b = -1;
assert (b >=1) : "Invalid Denominator";
int Ñ = a / b;
System.out.println (c);
}
}
What is the result of running the code with the ""ea option?
Answer options
- A. -10
- B. 0
- C. An AssertionError is thrown.
- D. A compilation error occurs.
Correct answer: C
Explanation
The assertion checks if 'b' is greater than or equal to 1; since 'b' is -1, this condition fails and an AssertionError is thrown. Options A and B are not correct as they do not correspond to the outcome of the assertion failure. Option D is also incorrect since there is no compilation error in the code.