wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt in Assert statement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubt in Assert statement" Watch "Doubt in Assert statement" New topic
Author

Doubt in Assert statement

Kalai Selvi
Ranch Hand

Joined: Jan 08, 2007
Posts: 45
public class TestMe
{
public static void main(String a[])
{
// Insert code here
}
}

1.assert true;
2.assert false;
3.assert false : true;
4.assert false == true;
5.assert false : false;

Which line inserted in the program causes an AssertionError to be thrown in TestMe.java? I tried all the options , they all work fine , i mean they dont throw any AssertionError.. Please correct me if i am wrong.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
You did enable assertions at run-time?


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Kalai Selvi
Ranch Hand

Joined: Jan 08, 2007
Posts: 45
I am sorry. I compiled it using -source 1.4 option, but somehow forgot to run using -ea. Now i did it and got the correct answer as i expected. only the first option doesnot throw AssertionError, since assert true is used. All the remaining options throw the Error.
Thanks for reminding me..
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Doubt in Assert statement