Wednesday, December 14, 2016

Write a JAVA program to illustrate sub class exception precedence over base class.

Write a JAVA program to illustrate sub class exception precedence over base class.

import java.io.*;
class Parent
{
  void msg()throws ArithmeticException
  {
     System.out.println("parent");
     int a=10,b=0;
     int c=a/b;
  }
}

class TestExceptionChild extends Parent
{
  void msg()
  {
    int arr[]=new int[4];
    System.out.println("child");
    arr[4]=4;
 
   }
   public static void main(String args[]){
   Parent p=new TestExceptionChild();
   try
   {
   p.msg();
   }
   catch(ArrayIndexOutOfBoundsException e)
   {
     System.out.println("ArrayIndexOutOfBounds Exception Caught");
   }
  }
}


Labels:

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home