GeeCON Prague 2014*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Que from JQPlus!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Que from JQPlus!!" Watch "Que from JQPlus!!" New topic
Author

Que from JQPlus!!

Ashok Paulraj
Ranch Hand

Joined: Jul 07, 2003
Posts: 78
Consider the following hierarchy of Exception classes :
Exception
+-- RuntimeException
+-- IndexOutOfBoundsException
+-- ArrayIndexOutOfBoundsException, StringIndexOutOfBoundsException
Which of the following statements are correct for a method that can throw ArrayIndexOutOfBounds as well as StringIndexOutOfBounds Exceptions but does not have try catch blocks to catch the same?

Options

Select 3 correct options.

1) The method calling this method will either have to catch these 2
exceptions or declare them in it's throws clause.


2) It's ok if it declares just 'throws ArrayIndexOutOfBoundsException'


3) It must declare 'throws ArrayIndexOutOfBoundsException,
StringIndexOutOfBoundsException'


4) It's ok if it declares just 'throws IndexOutOfBoundsException'


5) It does not need to declare any throws clause.

The given answers were: 2, 4 & 5.
I selected 1,2 & 4.
clarify the correct answers!!!
~ Shalini
Phil Rhodes
Ranch Hand

Joined: Dec 27, 2003
Posts: 65
IndexOutOfBoundsException, ArrayIndexOutOfBoundsException and
StringIndexOutOfBoundsException all inherit from RuntimeException
(indirectly in the case of ArrayIndexOutOfBoundsException and StringIndexOutOfBoundsException). Anything inheriting from
RuntimeException is considered a non-checked exception, and
does not have to be declared to be thrown by a method. However, while
you don't *have* to declare it, you *may* declare it. So in this case,
you could declare either one by itself, neither, or both.


A+, Network+, SCJP, SCWCD<br />preparing for SCBCD, SCEA, CompTIA I-Net+
 
GeeCON Prague 2014
 
subject: Que from JQPlus!!