• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Que from JQPlus!!

 
Ashok Paulraj
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic