Hi there, I'm a little confused with hiding and overriding. What're the definitions and usages of them? I mean, in what situation am I to hide a method and in what situation am I to override one? In both situation I can always use the method using super or parent's name whether it's hidden or overridden. Does it achieve something in distinguishing between these two nouns? Please help me out!
The only difference I can think of here is that when the method declared in parent class is a static method, then it is hidden by the derived class static method with same signature. Non-static methods in base class can be overridden by derived class method with same signature. For example,
Here is a helpful link to get more detailed information about this topic. SCJP Questions & Answers by Roseanne Zhang (2) Ritesh (Preparing for SCJP)
Ritesh<br /> <br />SCJP 1.4<br />IBM Test 340<br />IBM AIX V4.0 Certified Professional<br /> <br />Right actions for the future are the best apologies for wrong ones in the past.<br />- Tyron Edwards
Joined: Feb 17, 2004
Thanks for your reply and that article! Now I know the differece in ways to use of hiding and overriding, which prove what my teacher said, "static along with class, instance along with instance." However, I think that's just the rules of overriding, inheritance, and OO. I mean, the following statement (from that example): Base base = new Sub(); implies base is referenced to an instance of Sub. When we call an overridden method in the runtime, it will really execute the statements of that method in Sub. Isn't that just the rule of Java in OO? Namely, calling a static method with the class name (or reference name) is just the way of OO. I don't see any necessity of emphasizing hiding or overriding. I wonder if we can only show the difference between hiding and overriding in this tricky way. This is just my presumption, you guys can put it aside~
One word: polymorphism. Static methods do not participate in polymorphism so they are hidden, not overridden. What this means is that static methods are assigned at compile time while non-static/non-final methods are assigned at run time.