Hi,
I have a doubt in method overriding. If a superclass has a method that throws an Excpetion and the same method is overridden in subclass & the overridden method does not throw any exception, still that method should be called within try catch block in the implementing class. Why is it so??
See below example for clear idea on my doubt.
public class Shape
{
public void displayShape() throws Exception
{
System.out.println("displayShape in superclass ");
}
}
public class Circle extends Shape
{
public void displayShape()
{
System.out.println("displayShape in circle");
}
public static void main(
String[] args)
{
Shape c = new Circle();
c.displayShape();
}
}
Compiler says to sorround Circle's displayShape() in a try-catch block. Please let me know why this method should be sorrounded with try-catch block even when the overridden method in Circle class does not throw any Exception.