This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes About assertion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "About assertion" Watch "About assertion" New topic
Author

About assertion

Jack Lau
Ranch Hand

Joined: Aug 30, 2002
Posts: 166
Hello All,

I do not understand why the following answer is correct?
Q: Given an assert statement - assert exp1 : exp2;
A: Whenever assertions are enabled, exp1 always get evaluated

So I write a program to test it.



I run the above program with "java -ea -cp . TestAssert", it prints "AssertionError: b != b2"
However, I use "java -cp . TestAssert", it only prints "No AssertionError" but without "call me() ..." ?

Is the anwser wrong ?

Thanks in advance!!
Jack
Geoffrey Vlassaks
Greenhorn

Joined: May 12, 2004
Posts: 24
Assertions are disabled by default. You have to enable them by yourself (fe. using -ea). So for the second run statement, all the "assert" code will be skipped..

Greetz
Jack Lau
Ranch Hand

Joined: Aug 30, 2002
Posts: 166
Thanks!

Jack
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: About assertion
 
Similar Threads
SCJP exam Query....Assertions....
Assertion issue
When assertions are executed
Assertions
Assertion question from Dan's exam