This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android 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..
 
Don't get me started about those stupid light bulbs.
 
subject: Doubt in Assert statement
 
Similar Threads
Assertion problem?
doubt :assertion errors
About assertion
Assertions and unreachable statements
Can u explain this assert question