• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Assertion Quesion 2:can you explain the reason

 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
//
Can you explain the reason...

A. assert true;
B. assert false;
C. assert false : true;
D. assert false == true;
E. assert false: false;
 
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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".
 
Ranch Hand
Posts: 2023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also check this thread.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic