Java Programming :: Assertions
-
Which of the following statements is true?
-
Which statement is true?
-
Which statement is true about assertions in the Java programming language?
-
Which of the following statements is true?
-
Which of the following statements is true?
-
Which three statements are true?
- Assertion checking is typically enabled when a program is deployed.
- It is never appropriate to write code to handle failure of an assert statement.
- Assertion checking is typically enabled during program development and testing.
- Assertion checking can be selectively enabled or disabled on a per-package basis, but not on a per-class basis.
- Assertion checking can be selectively enabled or disabled on both a per-package basis and a per-class basis.
A.
If assertions are compiled into a source file, and if no flags are included at runtime, assertions will execute by default.
|
B.
As of Java version 1.4, assertion statements are compiled by default.
|
C.
With the proper use of runtime arguments, it is possible to instruct the VM to disable assertions for a certain class, and to enable assertions for a certain package, at the same time.
|
D.
When evaluating command-line arguments, the VM gives -ea flags precedence over -da flags.
|
A.
Assertions can be enabled or disabled on a class-by-class basis.
|
B.
Conditional compilation is used to allow tested classes to run at full speed.
|
C.
Assertions are appropriate for checking the validity of arguments in a method.
|
D.
The programmer can choose to execute a return statement or to throw an exception if an assertion fails.
|
A.
Assertion expressions should not contain side effects.
|
B.
Assertion expression values can be any primitive type.
|
C.
Assertions should be used for enforcing preconditions on public methods.
|
D.
An AssertionError thrown as a result of a failed assertion should always be handled by the enclosing method.
|
A.
It is sometimes good practice to throw an AssertionError explicitly.
|
B.
Private getter() and setter() methods should not use assertions to verify arguments.
|
C.
If an AssertionError is thrown in a try-catch block, the finally block will be bypassed.
|
D.
It is proper to handle assertion statement failures using a catch (AssertionException ae) block.
|
A.
In an assert statement, the expression after the colon ( : ) can be any Java expression.
|
B.
If a switch block has no default, adding an assert default is considered appropriate.
|
C.
In an assert statement, if the expression after the colon ( : ) does not have a value, the assert's error message will be empty.
|
D.
It is appropriate to handle assertion failures using a catch clause.
|