Consider the following program:
class Base {/* w ww . j av a 2s.c o m*/ public void foo() { assert true; // ASSERT_BASE } } class Derived extends Base { public void foo() { assert false; // ASSERT_DERIVED } } public class Main { public static void main(String []args) { try { Base base = new Base(); base.foo(); } catch(Exception e) { base = new Derived(); base.foo(); } } }
From the command line, this program is invoked as follows:
java -ea -da:Derived Main
Which one of the following options correctly describes the behavior of this program when it is run?
d)
The statement assert true; when executed will always succeed.
The statement assert true; when executed will always fail.
Remember that assertions are disabled by default, and -ea enables the assertion for the whole program.
However, -da disables assertions, and -da:Derived instructs the JVM to disable assertions in the Derived class.
Hence, the program completes execution normally without producing any output or throwing any exceptions.