| 5.24 | Assuming assertions are enabled, which of these assertion statements will throw an error? Select the two correct answers. -
assert true : true; -
assert true : false; -
assert false : true; -
assert false : false; |
| 5.25 | Which of the following are valid runtime options? Select the two correct answers. -
-ae -
-enableassertions -
-source 1.4 -
-disablesystemassertions -
-dea |
| 5.26 | What is the class name of the exception thrown by an assertion statement? Select the one correct answer. -
Depends on the assertion statement. -
FailedAssertion -
AssertionException -
RuntimeException -
AssertionError -
Error |
| 5.27 | What can cause an assertion statement to be ignored? Select the one correct answer. -
Nothing. -
Using appropriate compiler options. -
Using appropriate runtime options. -
Using both appropriate compiler and runtime options. |
| 5.28 | Given the following method, which statements will throw an exception, assuming assertions are enabled? static int inv(int value) { assert value > -50 : value < 100; return 100/value; } Select the two correct answers. -
inv(-50); -
inv(0); -
inv(50); -
inv(100); -
inv(150); |
| 5.29 | Which runtime options would cause assertions to be enabled for the class org.example.ttp.Bottle ? Select the two correct answers. -
-ea -
-ea:Bottle -
-ea:org.example -
-ea:org... -
-enableexceptions:org.example.ttp.Bottle -
-ea:org.example.ttp |
| 5.30 | What will be the result of compiling and running the following code with assertions enabled? public class TernaryAssertion { public static void assertBounds(int low, int high, int value) { assert ( value > low ? value < high : false ) : (value < high ? "too low" : "too high" ); } public static void main(String[] args) { assertBounds(100, 200, 150); } } Select the one correct answer. -
The compilation fails because the method name assertBounds cannot begin with the keyword assert . -
The compilation fails because the assert statement is invalid. -
The compilation succeeds and the program runs without errors. -
The compilation succeeds and an AssertionError with the error message "too low" is thrown. -
The compilation succeeds and an AssertionError with the error message "too high" is thrown. |
| 5.31 | Which statements are true about the AssertionError class? Select the two correct answers. -
It is a checked exception. -
It has a method named toString() . -
It has a method named getErrorMessage() . -
It can be caught by a try - catch construct. |
| 5.32 | Which of these classes is the direct superclass of AssertionError ? Select the one correct answer. -
Object -
Throwable -
Exception -
Error -
RuntimeError |
| 5.33 | Given the following command, which classes would have assertions enabled? java -ea -da:com... net.example.LaunchTranslator Select the two correct answers. -
com.example.Translator -
java.lang.String -
dot.com.Boom -
net.example.LaunchTranslator -
java.lang.AssertionError |