Out on HF and heard nobody, but didn't call CQ? Nobody heard you either. 73 de N7GH
Stefan Evans wrote:Yes the static methods from A are "inherited" by B
However they do no participate in polymorphism.
If B declares a static method with the same signature as one in A, it replaces that method, and effectively hides it, making A's version of it inaccessible.
So it doesn't count as 'overriding'
There is one case that you neglected to test in your example:
Do you think this should this code call A's F1 method or B's ?
Out on HF and heard nobody, but didn't call CQ? Nobody heard you either. 73 de N7GH
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Stefan Evans wrote:Yes the static methods from A are "inherited" by B
However they do no participate in polymorphism.
If B declares a static method with the same signature as one in A, it replaces that method, and effectively hides it, making A's version of it inaccessible.
So it doesn't count as 'overriding'
There is one case that you neglected to test in your example:
Do you think this should this code call A's F1 method or B's ?
s sivaraman wrote:
what do you mean by hiding in this context?
Stefan Evans wrote:If B declares a static method with the same signature as one in A, it replaces that method, and effectively hides it, making A's version of it inaccessible.
Rob Spoor wrote:The compiler does not use the actual type but the declared type. When you call b.F1(11), the compiler sees that b is declared as A and therefore calls A.F1(11).
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."
--- Martin Fowler
Have you tried it? Both quotes are correct; Stephan said that the superclass' version of the method is inaccessible in the subclass, (although Henry points out you can gain access to it by casting). Rob said that the method appropriate to the declared type is used.Partheban Udayakumar wrote:. . .
. . .Stefan Evans wrote:If B declares a static method with the same signature as one in A, it replaces that method, and effectively hides it, making A's version of it inaccessible.
. . .Rob Spoor wrote:The compiler does not use the actual type but the declared type. When you call b.F1(11), the compiler sees that b is declared as A and therefore calls A.F1(11).
Campbell Ritchie wrote: Stephan said that the superclass' version of the method is inaccessible in the subclass, (although Henry points out you can gain access to it by casting). Rob said that the method appropriate to the declared type is used.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."
--- Martin Fowler
Campbell Ritchie wrote:Most of it. You are not shadowing. You are hiding. We have an FAQ about that.
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."
--- Martin Fowler