Page: 2
6. Asserions
05. Given two files: 1. class One { 2. public static void main(String[] args) { 3. int assert = 0; 4. } 5. } 1. class Two { 2. public static void main(String[] args) { 3. assert(false); 4. } 5. } And the four command-line invocations: javac -source 1.3 One.java javac -source 1.4 One.java javac -source 1.3 Two.java javac -source 1.4 Two.java What is the result? (Choose all that apply.) A. Only one compilation will succeed. B. Exactly two compilations will succeed. C. Exactly three compilations will succeed. D. All four compilations will succeed. E. No compiler warnings will be produced. F. At least one compiler warning will be produced. Answer: -> B and F are correct. Class One will compile (and issue a warning) using the 1.3 flag, andclass Two will compile using the 1.4 flag. -> A, C, D, and E are incorrect based on the above. (Objective 2.3) 06. Which are true? (Choose all that apply.) A. It is appropriate to use assertions to validate arguments to methods marked public. B. It is appropriate to catch and handle assertion errors. C. It is NOT appropriate to use assertions to validate command-line arguments. D. It is appropriate to use assertions to generate alerts when you reach code that should notbe reachable. E. It is NOT appropriate for assertions to change a program’s state. Answer: -> C , D, and E are correct statements. -> A is incorrect. It is acceptable to use assertions to test the arguments of private methods. B is incorrect. While assertion errors can be caught, Sun discourages you from doing so.
Page: 2
1
2
|