| Author |
Assertions mock exam question
|
Poonam Thawani
Greenhorn
Joined: Oct 11, 2005
Posts: 13
|
|
Question 1. public class Test { 2. public static void main(String[] args) { 3. int x = 0; 4. assert (x > 0): "assertion failed"; 5. System.out.println("finished"); 6. } 7. } What is the result and why? A. finished B. Compilation fails. C. An AssertionError is thrown. D. An AssertionError is thrown and finished is output.
|
 |
Niranjan Deshpande
Ranch Hand
Joined: Oct 16, 2005
Posts: 1277
|
|
|
Answer is C. once AssertionError is thrown the string given in the assert's 2nd statement will be printed
|
SCJP 1.4 - 95% [ My Story ] - SCWCD 1.4 - 91% [ My Story ]
Performance is a compulsion, not a option, if my existence is to be justified.
|
 |
jiju ka
Ranch Hand
Joined: Oct 12, 2004
Posts: 302
|
|
Yes answer is C Got Exception in thread "main" java.lang.AssertionError: assertion failed at Test.main(Test.java:4) When run in -ea mode and compiled with -source 1.4 Printed Finished When run in -da mode ea stand for enable assertion and da stands for disable assertion. [ December 29, 2005: Message edited by: jiju ka ]
|
 |
 |
|
|
subject: Assertions mock exam question
|
|
|