posted 23 years ago
As far as i know, the overidding method( derived class method ) can throw subclasses of the exceptions or subset or all the exceptions
thrown by the overidden method( base class method ). Runtime exceptions can be
thrown by the overiding method even if the overidden method
does not throw them.
Also i can quote two points :
1. RuntimeException is a unchecked exception. So the overriding methods can throw unchecked exceptions even if the overidden method does not throw them
2. As with your replace RunTimeException in code of derived class with SQLException,
which is a checked exception, it is not a subclass of ClassNotFoundException, so code does not compile.
If i change the below code as
import java.sql.*;
class Base
{
public void aMethod() throws ClassNotFoundException, SQLException{}
}
class Derive extends Base
{
public void aMethod() throws SQLException{}
}
Code compiles fine as SQLException is one of the checked
exceptions thrown by Base class.