Hi,
The valid override says that the overriding method can throw fewer or no exception. However,the below is giving compiler error. As the eat() method is overridden in subclass,then the subclass version of the eat() should be called when we invoke a.eat().
class Animal
{
public void eat() throws Exception {
}
}
class Dog2 extends Animal
{
public void eat() {}
public static void main(
String arg[]) {
Animal a=new Dog2();
Dog2 d=new Dog2();
d.eat();
a.eat(); //This line gives compilation error
}
}
Thank you,
Srini