Jayesh Pawar wrote:-> In Java, static method belongs to the class and not to any particular instance of the class. Also, static methods are never inherited. If yes, then how come new B().printName() class the Base class method printName() ?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
Jayesh Pawar wrote:-> In Java, static method belongs to the class and not to any particular instance of the class. Also, static methods are never inherited. If yes, then how come new B().printName() class the Base class method printName() ?
Because B is an A, and you are allowed to called static methods via an instance (something, I should add, that many of us find horrible; although I suspect the founding fathers had their reasons).
Mike Simmons wrote:Well, it is inheritance as the JLS defines the term. I don't know what "static methods are never inherited" is even supposed to mean. Must use some other definition of inheritance.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Mike Simmons wrote:Where does that idea come from?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Jayesh Pawar wrote:
Also, static methods are never inherited.
Winston Gutkowski wrote:To me, static methods or behaviour are not "inherited" in any sense that I understand the word, since there is no hierarchy involved.
Wikipedia:Inheritance wrote:In classical inheritance where objects are defined by classes, classes can inherit attributes and behavior from pre-existing classes called base classes, superclasses, parent classes or ancestor classes. The resulting classes are known as derived classes, subclasses or child classes. The relationships of classes through inheritance gives rise to a hierarchy.
Winston Gutkowski wrote:They may be "seen" or "acquired" by subclasses; but that was a language decision - as was the business of allowing static methods to be referenced via instances.
Mike Simmons wrote:
Wikipedia:Inheritance wrote:In classical inheritance where objects are defined by classes, classes can inherit attributes and behavior from pre-existing classes called base classes, superclasses, parent classes or ancestor classes. The resulting classes are known as derived classes, subclasses or child classes. The relationships of classes through inheritance gives rise to a hierarchy.
This all applies 100%, regardless of whether attributes and behavior are static or not.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:If I design a language where static methods are ONLY visible by the class that defines it, I can still call it an OO language. If I specify the same rule for instance methods, it is absolutely NOT one.
Winston Gutkowski wrote:And I say again, if "static inheritance" really is inheritance: I should be able to override public static x() and call super.x() from my overridden implementation. But I can't; I can only "mask" it.
To me, static methods or behaviour are not "inherited" in any sense
OCPJP 6 86%
Mike Simmons wrote:So is this all "what inheritance means to me"
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Nikhil Sagar wrote:
To me, static methods or behaviour are not "inherited" in any sense
i am totally agree with Winston's this statement because as i know that all the decisions about static methods are taken by the compiler at compile time. So, i think there is no need to inherit static methods.
Winston Gutkowski wrote:
Mike Simmons wrote:So is this all "what inheritance means to me"
Not at all. I provided a perfectly straightforward argument in my second sentence
Mike Simmons wrote:Which second sentence is that?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:I've only seen one thing in the Wiki page that refutes anything I've said: the business of code re-use.
Winston Gutkowski wrote:It could be argued that allowing subclasses to 'see' a superclass's static method is a form of code re-use;
Winston Gutkowski wrote:but "masking" most certainly is not.
Winston Gutkowski wrote:
As for references, I see no reference anywhere in the Wikipedia page to "static inheritance"; nor are there any examples of it applying to static methods. Could that perhaps mean that, like me, they regard inheritance as being instance-based?
Winston Gutkowski wrote:Let me turn it around: Other than the JLS, can you find any generally accepted definition of "inheritance" as it applies to static methods?
What You Can Do in a Subclass
A subclass inherits all of the public and protected members of its parent, no matter what package the subclass is in. If the subclass is in the same package as its parent, it also inherits the package-private members of the parent. You can use the inherited members as is, replace them, hide them, or supplement them with new members:
...
You can write a new static method in the subclass that has the same signature as the one in the superclass, thus hiding it.
...
Winston Gutkowski wrote:
And I say again, if "static inheritance" really is inheritance: I should be able to override public static x() and call super.x() from my overridden implementation.
Mike Simmons wrote:
Winston Gutkowski wrote:To me, static methods or behaviour are not "inherited" in any sense that I understand the word, since there is no hierarchy involved.
Ummm... how is there no type hierarchy involved? Class B extends A. There you go.
Mike Simmons wrote:So Winston, are you dropping this one? Because it seems pretty straightforward to me.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:Show me any reference to or example of “inheritance” using static fields or methods outside the JLS or the tutorials and I will bow and grovel at your feet.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:It seems to me that you went all around the houses to find the “2nd sentence” that was actually in my previous post.
Mike Simmons wrote:So perhaps you could quote the sentence you're actually talking about?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
OCPJP 6 86%
Nikhil Sagar wrote:Looks like jayesh (original poster) got a lot more than he was expecting.
![]()
![]()
![]()
![]()
![]()
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
brevity is the soul of wit - shakepeare. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|