an overriding method doesn't have to declare any exceptions that it will never throw, regardless of what the overridden method declares.
What does this statement mean?
is it correct or not ?
means if an overridden method has declared an exception.It is not necessary for the overridding method to declare that exception .
if it is correct.
Why the following program is giving compile time error?
please explain me about this
class Animal {
public void eat() throws Exception {
// throws an Exception
}
}
class Dog2 extends Animal {
public void eat() { // no Exceptions }
public static void main(
String [] args) {
Animal a = new Dog2();
Dog2 d = new Dog2();
d.eat();
a.eat();
}
}
C:\practice>javac Dog2.java
Dog2.java:16: unreported exception java.lang.Exception; must be caught or declar
ed to be thrown
a.eat(); // compiler error -
^
1 error
[ February 26, 2007: Message edited by: anil kumar ]