This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Assertion Quesion 2:can you explain the reason Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Assertion Quesion 2:can you explain the reason" Watch "Assertion Quesion 2:can you explain the reason" New topic
Author

Assertion Quesion 2:can you explain the reason

Supriya Nimakuri
Ranch Hand

Joined: May 23, 2006
Posts: 83
1. public class Test{
2. public static void main( String[] argv ){
3. // insert statement here
4. }
5. }
Which statement, inserted at line 3, produces the following output?

Exception in thread �main� java.lang.AssertionError: true
at Test.main(Test.java:3)
//
Can you explain the reason...

A. assert true;
B. assert false;
C. assert false : true;
D. assert false == true;
E. assert false: false;
Naseem Khan
Ranch Hand

Joined: Apr 25, 2005
Posts: 809
answer is c--->>assert false : true;

When assert condition gets false, it throws AssertionError. On the right hand side of colon, you can pass any object which can be converted to String equivalent.

e.g,

assert false: new Object();
assert false: new Integer(4);

Both are legal.

In your case, true gets boxed to Boolean object. Then toString() method is called on bollean object resulting in corresponding string equivalent "true".


Asking Smart Questions FAQ - How To Put Your Code In Code Tags
wise owen
Ranch Hand

Joined: Feb 02, 2006
Posts: 2023
Also check this thread.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Assertion Quesion 2:can you explain the reason
 
Similar Threads
assertions
Can u explain this assert question
assertion related(mock)
mock: assertion
Use of Assert in Java