Exception handling with method overriding

It gives error but when we write ArithmeticException in place of IOException it does not give error.

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 arg[])

      {

            Parent p=new TestExceptionChild();

            p.msg();

      }

}

Exception Handling With Method Overriding -Error.PNG

import java.io.*;

class Parent

{

      void msg()

      {

            System.out.println("Parent");

      }

}

class TestExceptionChild extends Parent

{

      void msg() throws ArithmeticException

      {

            System.out.println("TestExceptionChild");

      }

      public static void main(String arg[])

      {

            Parent p=new TestExceptionChild();

            p.msg();

      }

}

Exception Handling With Method Overriding.PNG

, , , , , ,

Leave a Reply