| Author |
throwing an exception
|
Maria Garcia
Ranch Hand
Joined: Jul 14, 2002
Posts: 86
|
|
|
if a method in a superclass does NOT throw an exception, and if the subclass overrides the method, can the latter throw an exception ?
|
SCJP 1.4
|
 |
Anthony Villanueva
Ranch Hand
Joined: Mar 22, 2002
Posts: 1055
|
|
No. Suppose class A has method m() which throws exceptions X, Y and Z. Suppose class B extends A and overrides m(). Then m() of B can only throw: 1. X, Y, Z (some or all) 2. subclasses of X, Y, Z (some or all) 3. none at all but m() cannot throw exceptions W or U.
|
 |
Valentin Crettaz
Gold Digger
Sheriff
Joined: Aug 26, 2001
Posts: 7610
|
|
m() (in the subclass) may throw any RuntimeException or Error, though For more information, please read: JLS 11.2 Compile-Time Checking of Exceptions [ July 24, 2002: Message edited by: Valentin Crettaz ]
|
SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
|
 |
Anthony Villanueva
Ranch Hand
Joined: Mar 22, 2002
Posts: 1055
|
|
Yeah I meant checked exceptions X, Y, Z, W or U. Hope it's clear now
|
 |
Maria Garcia
Ranch Hand
Joined: Jul 14, 2002
Posts: 86
|
|
thank you for your help
|
 |
 |
I agree. Here's the link: jrebel
|
|
subject: throwing an exception
|
|
|