Please find my code below, I want to clear my concept on overriding along with throws exceptions. Will below provided code work, if yes then why.? I'm asking this question because there is no direct parent child relation between IOException and ArithmeticException.
public class TestExceptionChild {
public static void main(String[] args) {
Parent parent = new Child();
try {
parent.msg();
} catch (IOException e) {
e.printStackTrace();
}
}
}
class Parent{
void msg() throws IOException{
System.out.println("parent");
}
}
class Child extends Parent{
void msg() throws ArithmeticException{
System.out.println("child");
}
}