File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Can u explain this assert question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Can u explain this assert question" Watch "Can u explain this assert question" New topic
Author

Can u explain this assert question

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)

A. assert true;
B. assert false;
C. assert false : true;
D. assert false == true;
E. assert false: false;

Which is correct option C or E..and why
Karol Kisielewski
Greenhorn

Joined: Jun 28, 2006
Posts: 8
Originally posted by Supriya Nimakuri:
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)

A. assert true;
B. assert false;
C. assert false : true;
D. assert false == true;
E. assert false: false;

Which is correct option C or E..and why


Of course correct is C. If the first part of assert statement resolve to false, then AssertionError is thrown. The second part is the message which will be printed. The value of the message can be any expression which return some value.
BTW. I had the same question on real exam. Where did you get it from?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can u explain this assert question