There are many rules if we talk about methodoverriding with exception handling. The Rules are as follows:
import java.io.*; class Parent{ void msg(){System.out.println("parent");} } class TestExceptionChild extends Parent{ void msg()throws IOException{ System.out.println("TestExceptionChild"); } public static void main(String args[]){ Parent p=new TestExceptionChild(); p.msg(); } }
import java.io.*; class Parent{ void msg(){System.out.println("parent");} } class TestExceptionChild1 extends Parent{ void msg()throws ArithmeticException{ System.out.println("child"); } public static void main(String args[]){ Parent p=new TestExceptionChild1(); p.msg(); } }
import java.io.*; class Parent{ void msg()throws ArithmeticException{System.out.println("parent");} } class TestExceptionChild2 extends Parent{ void msg()throws Exception{System.out.println("child");} public static void main(String args[]){ Parent p=new TestExceptionChild2(); try{ p.msg(); }catch(Exception e){} } }
import java.io.*; class Parent{ void msg()throws Exception{System.out.println("parent");} } class TestExceptionChild3 extends Parent{ void msg()throws Exception{System.out.println("child");} public static void main(String args[]){ Parent p=new TestExceptionChild3(); try{ p.msg(); }catch(Exception e){} } }
import java.io.*; class Parent{ void msg()throws Exception{System.out.println("parent");} } class TestExceptionChild4 extends Parent{ void msg()throws ArithmeticException{System.out.println("child");} public static void main(String args[]){ Parent p=new TestExceptionChild4(); try{ p.msg(); }catch(Exception e){} } }
import java.io.*; class Parent{ void msg()throws Exception{System.out.println("parent");} } class TestExceptionChild5 extends Parent{ void msg(){System.out.println("child");} public static void main(String args[]){ Parent p=new TestExceptionChild5(); try{ p.msg(); }catch(Exception e){} } }