Originally posted by Emma Peel:
In the Sun's Java Tutorial, it says: "A subclass cannot override methods that are declared static in the superclass. In other words, a subclass cannot override a class method. A subclass can hide a static method in the superclass by declaring a static method in the subclass with the same signature as the static method in the superclass".
So what is the difference between overriding a method and hiding it?
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Originally posted by Emma Peel:
Thanks for the clarification.
The only thing I couldn't get to work is using the "super" reference to call the staticMethod (after I removed the static designation from both staticMethods in your original example).
I removed the instantiation for the "sup" type Super Class object, and I inserted "super.staticMethod(3);" after the"((Super) sub).staticMethod(2);" statement,and I got a the following compile error: "Sub.java:16: non-static variable super cannot be referenced from a static context".
The Sun Tutorial say "super.overriddenMethodName();" is how to do it. Do you know what I am doing wrong?
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Originally posted by Emma Peel:
I don't understand your example. I thought a static method could not access an instance variable, though the reverse can occur. I thought that class-member variables could either be static or instance variables. Therefore, no static variable could have the same name as an instance variable in the same class.
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
See ya later boys, I think I'm in love. Oh wait, she's just a tiny ad:
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
|