Forums Register Login

About assertion

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
Thanks!

Jack
See ya later boys, I think I'm in love. Oh wait, she's just a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 735 times.
Similar Threads
Assertion issue
Assertions
SCJP exam Query....Assertions....
Assertion question from Dan's exam
When assertions are executed
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 08:53:08.