Originally posted by Jesper Young:
About the static method: The error message that the compiler gives you is indeed strange, because static methods cannot be overridden.
According to the Java Language Specification section 8.4.8, a static method can hide (but not override) other static methods in superclasses.
The fact that you get an error is correct; in section 18.104.22.168 the JLS says:
"A method declaration must not have a throws clause that conflicts (�8.4.6) with that of any method that it overrides or hides; otherwise, a compile-time error occurs."
It's just the wording of the error message from the compiler that's incorrect - it should have said "fun() in B cannot hide fun() in A" instead of "override".
The Java compiler isn't perfect, it's also just a piece of software written by a human being...
by over-riding we can have polymorphic calls like this
Parent parent = new Child();
by hiding we can just block Parent methods to have our own child implementation. ( No polymorphic calls.)
(see my example posted above)
Originally posted by Srinivasan thoyyeti:
Wanna add one more point: RuntimeExceptions are not checked. we can decalre a method throw Any RuntimeException irrespective of parent throwing it or not.
[ August 14, 2007: Message edited by: Srinivasan thoyyeti ]