Still Learing..
Originally posted by Campbell Ritchie:
The implementation of a static method goes with the class, so you would have to implement it inside the interface, but as Arulk Pillai has told you, you mustn't implement methods in an interface.
Still Learing..
Originally posted by Jesper Young:
Static methods are not inherited - not from superclasses and not from interfaces.
That code doesn't work because it tries to inherit the static method from myInterface into myClass.
Still Learing..
Originally posted by Ernest Friedman-Hill:
Anyway, the real answer as to why this isn't allowed is that it's not. At some point you just have to accept that Java is what Java is; the folks who designed the language made some choices, and you have to live with those choices.
Still Learing..
"I'm not back." - Bill Harding, Twister
Originally posted by jaspreet atwal:
Thanks for your reply Ernest! I can live with that...
I was just wondering if there is some logic behind all this, something that will help me keep this in my mind instead of cramming/memorizing it.
Java hobbyist.
He who asks a question is a fool for five minutes; he who does not ask a question remains a fool forever - Chinese proverb
Not in the conventional sense no - static methods can do something called "shadowing". This means any class may possess a static method with the same name (but possibly with different return type and arguments) as any other class, and this is legal. The interpreter figures which one to invoke by the declared class type on which it is invoked. In your case, you're invoking it on a declared type of class B (b.printHello()). Hence it really invokes B.printHello() so you get the output "Hello B".Doesn't this indicate that the printHello() method of A was overridden by B?
Java hobbyist.
He who asks a question is a fool for five minutes; he who does not ask a question remains a fool forever - Chinese proverb
Have a look through your book and see how much is actually printed about shadowing and overriding.Originally posted by Shikhar Madhok:
Did I miss a few chapters, or is the term generally not used with java very often?
It's not used that often. In practise almost all of what you do with Java will (and should) be OOP - so you'll not use static methods and variables much, less in such confusing situations.Did I miss a few chapters, or is the term generally not used with java very often?
You down with OOP? Yeah you know me!
Understanding is Everything - Peter Lord