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

It should throw a runtime error..

 
sonir shah
Ranch Hand
Posts: 435
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Consider the following class :

Which of the following statements are true if the above program is run with the command line :
java Test closed
Ans :It will end without exceptions and will print nothing
According to me it should throw ArrayIndexOutOfBoundsException at Runtime..
Am I wrong?
Sonir
 
Arathi Rajashekar
Ranch Hand
Posts: 112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by sonir shah:
Consider the following class :

Which of the following statements are true if the above program is run with the command line :
java Test closed
Ans :It will end without exceptions and will print nothing
According to me it should throw ArrayIndexOutOfBoundsException at Runtime..
Am I wrong?
Sonir

What happening is when first if statement is checked it will be false and it won't execute the second if statement. So the output doesnot print anything. The second else statement belongs to inner if statement and not to outer, that is the reason why it won't throw arrayindexoutof bounds exception. Hope it helps
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic