Clemonte Johnstone wrote:1) Why throws Exception is not allowed if supplemented below?
Because when you override a method, the new method may not add any new checked exception types.
In your example, throwing ArrayIndexOutOfBoundsException is OK, because (a) it's unchecked, and (b) it's a subtype of IndexOutOfBoundsException. You're not throwing a new checked exception; you're saying you won't throw any IndexOutOfBoundsException other than the more specific subtype ArrayIndexOutOfBoundsException. That's allowed, even if these were checked exceptions (which they are not).
But throws Exception is definitely a new type of checked exception. It includes the unchecked IndexOutOfBoundsException and ArrayIndexOutOfBoundsException, but also may include many other things like IOException. It could be anything. Definitely not allowed by the super method declaration.
Clemonte Johnstone wrote:2) Can we say that we are overriding the method declaration in the Subclass?
Yes. You are overriding it, providing a method with the same signature. You are not implementing it, since it's still abstract, no implementation, but you are overriding it. This can be done to modify the method in a few allowed ways, including (a) making the method more accessible (not less), (b) changing the return type to a more specific subtype, if applicable, (c) changing the throws clause to a more restrictive (not less) list of checked types (plus any unchecked types you like), and (d) adding a new JavaDoc comment (which hopefully modifies but does not violate the contract of the super method -- that's up to you though, the compiler doesn't care)
If you are using a rototiller, you are doing it wrong. Even on this tiny ad:
SKIP - a book about connecting industrious people with elderly land owners