aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Assertions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Assertions" Watch "Assertions" New topic
Author

Assertions

Marcelo Ortega
Ranch Hand

Joined: May 31, 2005
Posts: 519

First off, if a question were to simply ask "What would be the result?" on a question involving assterions on the exam, do we assume that assertions are enabled or disabled at runtime? Compiled with or not compiled with?

Secondly...

What is the result of the following question?



A. An AssertionError is thrown and "Continue..." is output.
B. An AssertionError is thrown with the message �No good�.
C. An AssertionError is thrown with the message �Ok�.
D. Continue...
E. Compilation fails.

Answer givenis E.
I also think it won't compile due to incorrect syntax on line 1???
But i don't trust this mock's results because they have alot of errors in their answers.


SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCJD, SCEA/OCMJEA

Live life to an interface, not an implementation!
Richard Martin
Greenhorn

Joined: Jun 06, 2005
Posts: 2
assert statements can take 2 forms

Ex 1: assert (boolean expression);

or

Ex 2: assert (boolean expression) : "houston we have a problem"; -- (in this example the second part can be anything that returns a value, you can send it of to a method as long as the method returns a value, the result will be converted to a string and displayed with the stack trace)

The reason this code will fail to compile is because (val > 0) ? �Ok� : �No good� will not result in a boolean value, it will result in a String. The first part of an assert statement must always result in a boolean value, if you have a second expression as in example 2 that must always result in a value.


The first question is a good one though, from a similar point if they use assert as a variable name in a question are we to assume assertions are enabled?
Marcelo Ortega
Ranch Hand

Joined: May 31, 2005
Posts: 519

So yor saying the following will compile fine:

assert (val > 0) ? true : false;

??
 
jQuery in Action, 2nd edition
 
subject: Assertions