File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt in Assert statement

 
Kalai Selvi
Ranch Hand
Posts: 45
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7729
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You did enable assertions at run-time?
 
Kalai Selvi
Ranch Hand
Posts: 45
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic