JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Great thanks,<br />Luco Zhao
Ramu Kalvakuntla<br />SCJP,SCWCD,IBM Certified Specialist - IBM VisualAge for Java
Originally posted by Marilyn deQueiroz:
3. which one does polymorphism do (overloading or overriding)
Overriding
Reid - SCJP2 (April 2002)
Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Originally posted by Leif Huang:
Would someone please tell me what the diff. between "overriden" and "hidden" is?
(1) A static method can not be overridden. is the reason because it is implicity "final" as stated in JLS? Why is it implicity "final"? As I known, "final" is just an ADD_ON tag for static methods, I mean they can be either final or not.
A method can be declared final to prevent subclasses from overriding or hiding it. It is a compile-time error to attempt to override or hide a final method.
(2) when a static method is hidden, super.staticMethod() does not work. Is the reason because it is a static method? or Java's rule? other reason?
An attempt to reference the current object using the keyword this or the keyword super in the body of a class method results in a compile-time error.
(3) Can I "hiding" an instance method so that late-binding is not applied? It can be resolved in compile-time.
An attempt to reference the current object using the keyword this or the keyword super in the body of a class method results in a compile-time error.
Originally posted by Leif Huang:
But if you use them in an instance method, super.doIt() or super.staticDoIt() both are OK since a static method could be called either by an instance var or by the class name as long as it is not in a static context.
If the invocation mode is static, no target reference is needed and overriding is not allowed. Method m of class T is the one to be invoked.
I am still confused about the overridden and hidden. I can answer correctly from the output of your sample program. I understand why the overriding methods are computed at runtime by the object type because they need to achieve dynamic polymorphism. But I still do not understand why the static methods are hidden, are not overridden and computed at compile-time (hiding of fields too) by the reference type. Do you know the design concept behind?