• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can u explain this assert question

 
Supriya Nimakuri
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic