This week's book giveaway is in the JavaFX forum.
We're giving away four copies of Introducing JavaFX 8 Programming and have Herbert Schildt 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 Introducing JavaFX 8 Programming this week in the JavaFX forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubt in Assert statement" Watch "Doubt in Assert statement" New topic

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 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..
I agree. Here's the link:
subject: Doubt in Assert statement
It's not a secret anymore!