wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes It should throw a runtime error.. 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 "It should throw a runtime error.." Watch "It should throw a runtime error.." New topic
Author

It should throw a runtime error..

sonir shah
Ranch Hand

Joined: Nov 01, 2001
Posts: 435
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

Joined: Nov 20, 2001
Posts: 112
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


Arathi<br />Sun Certified Java Programmer
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: It should throw a runtime error..