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: Java Programming Lab
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home