• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

When assertions are executed

 
Bon Thanh
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a question from the ePractice exams for 310-055 purchased directly from Sun Microsystems.

Given:



Which is true?

A - An assertion error will occur at runtime.
B - The command-line invocation java -ea TestAssert will produce no error and the output "more info ".
C - The command-line invocation java -ea TestAssert will produce no error and the output "after assert ".
D - The command-line invocation java -ea TestAssert will produce no error and the output "more info after assert ".
E - The command-line invocation java -ea TestAssert will produce no error and the output "after assert more info ".

Sun's answer is:
Option A is correct. The command-line enables assertions, and more info is added to the stack trace before the program ends at line 3 with an AssertionError.

I disagree. Assertions are disabled by default at runtime. The question did not provide the command-line being used. I think the correct answer should be (which is not one of the options provided):
The command-line invocation java -ea TestAssert will produce an assertion error and the output "more info ".

Can someone please confirm?

Thank you!
Bonnie
 
Dejan Miler
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree whit you my friend.
This question is little misleading.
But let me ask you something.
When this error will occur ?

The command-line invocation java -ea TestAssert will produce an assertion error and the output "more info ".

At runtime or during compiling time ?
Of course at runtime.
Then first logical answer is A !

Dejan.
 
Bon Thanh
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, Dejan, if you put it that way, then I agree that the logical answer out of the answers provided would be A.
Thanks!
 
S Bhanage
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Option A is the only possible answer.

Without "-ea" option, the assertion error, if any, is suppressed.
But with "-ea" it is displayed on the console.


Hence output is different with different option of executing the code.
But in any case choice A is always going to happen.

So Option A is correct answer.
 
Bon Thanh
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interesting. I thought disabling assertions meant that they weren't even processed. Since when assertions are enabled, your application's performance is affected.
So you're saying that enabling or disabling assertions just means whether or not they are displayed on the console? But assertion statements are always processed?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic