i have this program in java
public class PolyTest
{
public static void main(String... arg)
{
Animal a = new Animal();
Horse b = new Horse();
Animal c = new Horse();
a.eat();
b.eat();
c.eat();
}
}
class Animal
{
public void eat() throws IndexOutOfBoundsException
{
System.out.println("Animal Eating");
}
}
class Horse extends Animal
{
@Override
public void eat()
{
System.out.println("Horse Eating");
}
}
now, surprisingly it works without any error in-spite of no try catch block or thrown clause in main method.
1. why a.eat()
is not giving any error in main method ?
2. when I change IndexOutOfBoundsException
to simply Exception
, it is a compile time error. why ?
read something about this in kathy sierra's SCJP exam guide, but couldn't understand the concept here.