Static initializers (§8.7), class variable initializers, and instance initializers or instance variable initializers within named classes and interfaces (§8.3.2), must not result in a checked exception; if one does, a compile-time error occurs. No such restriction applies to instance initializers or instance variable initializers within anonymous classes (§15.9.5).
I can't detect any redefining att all.
Consider:which results in:
If callme() would have been successfully redifined I believe the
result should have been:
Eclipse thinks that I should access call me in a static way though and
not via an object reference like in the last case.
The evidence and my memory both suggest that it is impossible
to override static methods. (It looks like they have to follow
some rules about similar methods signatures when having the
same name though.)
We are not overriding the method and the compiler will interpret the statement as
That's why, it is calling the correct method thats in A. Only thing is that there is some gotcha regarding redefining the static
method in a subclass with the same name. Redefining doesn't mean overriding and yes you are correct, static methods can
never be overriden.
I think so this statement might clarify this doubt, i am copying it from this
Actually static methods are not overridden in the true sense. They are 'hidden' by subclass method of same signature and return type. So, they do not participate in dynamic binding. Thus irrespective of which refernce a superclass is holding, it JVM invokes superclass method, if method in question is static.
So i guess these are the rules in case of redefining static methods.
1- The redefined method in subclass must have same signature.
2- It must have same return type.
3- It must now throw any checked exceptions if the super-class method is not throwing in order to properly hide the parent class method.
When we say this
In such a situation, i guess this rule will impy
4- Thus irrespective of which refernce a superclass is holding, it JVM invokes superclass method, if method in question is static.
Why i am saying this because when i have compiled the code in Eclipse, it's giving me the following error
Exception is not compatible with throws clause in A.callme()
Now i am waiting for other fellows to reply. Interesting thread and question Anu.
Read my last reply and give your opinion what do you think, am i correct in the specifying the explanation above.
I just begin to hate Java for its ambiguity.Today morning I began to think , now I'm ready for real exam but now I am knowing nothing for sure. Experts where are you ? Any opinion about this tricky question