my dog learned polymorphism
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Assertions mock exam question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Assertions mock exam question" Watch "Assertions mock exam question" New topic

Assertions mock exam question

Poonam Thawani

Joined: Oct 11, 2005
Posts: 13
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: 306
Yes answer is C

Exception in thread "main" java.lang.AssertionError: assertion failed
at Test.main(
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 ]
I agree. Here's the link:
subject: Assertions mock exam question
jQuery in Action, 3rd edition