If SuperClass declares an exception, then the SubClass can only declare the child exceptions of the exception declared by the SuperClass, but not any other exception, what if I'm declaring checked exception in parent method?
what if I'm declaring checked exception in parent method?
class SuperClass6 {
// SuperClass doesn't declare any exception
void method()throws IOException
{
System.out.println("SuperClass");
}
}
// SuperClass inherited by the SubClass
class SubClass6 extends SuperClass {
// method() declaring Unchecked Exception ArithmeticException
void method() throws FileNotFoundException
{
// ArithmeticException is of type Unchecked Exception
// so the compiler won't give any error
System.out.println("SubClass");
}
// Driver code
public static void main(String args[])
{
SuperClass s = new SubClass();
s.method();
}
}