| Author |
Question on Assertion?
|
Seenu Reddy
Ranch Hand
Joined: Apr 03, 2002
Posts: 108
|
|
Hi All, I am new to Assertion topic. Could you please answer my question and explain? Assuming assertions are enabled, which of these assertion statement throw an error? a) assert true : true; b) assert true : false; c) assert false : true; d) assert false : false; My ans : c, d
|
Thanks,<br />Seenu<br />SCJP1.4,SCBCD1.3,Next-->SCWCD1.4
|
 |
Nicholas Cheung
Ranch Hand
Joined: Nov 07, 2003
Posts: 4982
|
|
You are correct, the answers should be c and d, and they are easy to verify by writing a test program. For assertion, there are 2 forms: 1. assert expression1 2. assert expression1 : expression2 expression 1 must result in a boolean expression. Whenever expression1 is false, AssertError will be thrown. Thus, c and d give AssertError. expression2 is the message that you want to pass to the AssertError. Even you pass in a boolean value, it will be converted to String, and printed out.
Details can be found from: http://www.javaworld.com/javaworld/jw-11-2001/jw-1109-assert.html Nick
|
SCJP 1.2, OCP 9i DBA, SCWCD 1.3, SCJP 1.4 (SAI), SCJD 1.4, SCWCD 1.4 (Beta), ICED (IBM 287, IBM 484, IBM 486), SCMAD 1.0 (Beta), SCBCD 1.3, ICSD (IBM 288), ICDBA (IBM 700, IBM 701), SCDJWS, ICSD (IBM 348), OCP 10g DBA (Beta), SCJP 5.0 (Beta), SCJA 1.0 (Beta), MCP(70-270), SCBCD 5.0 (Beta), SCJP 6.0, SCEA for JEE5 (in progress)
|
 |
Seenu Reddy
Ranch Hand
Joined: Apr 03, 2002
Posts: 108
|
|
Nick, Thanks for your response and explanation. Regards, Seenu
|
 |
 |
I agree. Here's the link: jrebel
|
|
subject: Question on Assertion?
|
|
|