| Author |
Static members | Inheritance
|
Puja Sinha
Greenhorn
Joined: May 25, 2011
Posts: 27
|
|
Hi,
I ran the following code :
It printed :
This is the parent class
parent
Why does this happen , when we say that the static members are not inherited.
Thanks in advance.
Puja
|
 |
Matthew Brown
Bartender
Joined: Apr 06, 2010
Posts: 3860
|
|
Puja Sinha wrote:Why does this happen , when we say that the static members are not inherited.
We don't say that (well, maybe some people do ) - we say they are not overridden.
|
 |
Ikpefua Jacob-Obinyan
Ranch Hand
Joined: Aug 31, 2010
Posts: 394
|
|
Matthew Brown wrote:
We don't say that (well, maybe some people do  ) - we say they are not overridden.
Hello Guys...@Matthew I am tempted to believe that a lot of people 'say-and-think' that static members are NOT inherited, I have encountered that in this forum and other forums. One other thing I want to say is that static methods CANNOT be polymorphically overridden rather 'redifined'.
Regards
Ikpefua.
|
OCPJP 6.
In Your Pursuit Towards Certification, NEVER Give Up.
|
 |
Tommy Delson
Ranch Hand
Joined: Apr 13, 2011
Posts: 206
|
|
Matthew Brown wrote:
Puja Sinha wrote:Why does this happen , when we say that the static members are not inherited.
We don't say that (well, maybe some people do  ) - we say they are not overridden.
I think your guys mixed up with Polymorphism, Inheritance, and Overridden Static Members. Below is a modified version that may help....
|
OCPJP6-05-11
"Your life is in your hands, to make of it what you choose."
|
 |
Tommy Delson
Ranch Hand
Joined: Apr 13, 2011
Posts: 206
|
|
Ikpefua Jacob-Obinyan wrote:
Matthew Brown wrote:
We don't say that (well, maybe some people do  ) - we say they are not overridden.
Hello Guys...@Matthew I am tempted to believe that a lot of people 'say-and-think' that static members are NOT inherited, I have encountered that in this forum and other forums. One other thing I want to say is that static methods CANNOT be polymorphically overridden rather 'redifined'.
Regards
Ikpefua.
Here is what Ikpefua Jacob meant:
Recap from K & B book: Chapter 2, Page 151
Finally, remember that static methods can't be overridden! This doesn't mean they
can't be redefined in a subclass, but redefining and overriding aren't the same thing.
Let's take a look at an example of a redefined (remember, not overridden), static
method:
Running this code produces the output:
a a a
|
 |
Seetharaman Venkatasamy
Ranch Hand
Joined: Jan 28, 2008
Posts: 5575
|
|
http://www.coderanch.com/t/368681/java/java/statics-inherited
|
 |
Ikpefua Jacob-Obinyan
Ranch Hand
Joined: Aug 31, 2010
Posts: 394
|
|
Tommy Delson wrote:I think your guys mixed up with Polymorphism, Inheritance, and Overridden Static Members.
Hello Tommy, your 'modus-operandi' of using codes to dialogue in this forum is from my point of view the most effective way to clarify doubts in Java. In addition I want to mention that if you carefully read Matthew and Puja's posts you will notice that there was NO "mix-up", Puja placed his arguments or doubts and Matthew replied with a simple and straight forward answer that you and I followed up. So who's mixing up what?
Regards
Ikpefua
|
 |
Tommy Delson
Ranch Hand
Joined: Apr 13, 2011
Posts: 206
|
|
Ikpefua Jacob-Obinyan wrote:
Tommy Delson wrote:I think your guys mixed up with Polymorphism, Inheritance, and Overridden Static Members.
Hello Tommy, your 'modus-operandi' of using codes to dialogue in this forum is from my point of view the most effective way to clarify doubts in Java. In addition I want to mention that if you carefully read Matthew and Puja's posts you will notice that there was NO "mix-up", Puja placed his arguments or doubts and Matthew replied with a simple and straight forward answer that you and I followed up. So who's mixing up what?
Regards
Ikpefua
Yup, that's TRUE using codes to clarify doubt in Java is the best approach to understand and learn how Java works. The Compiler is an ultimate Tool to clarify our doubts so, utilize it as much as we could.
Sound like you're ready for the Final SCJP Exam....go for it if you're ready!
|
 |
Ikpefua Jacob-Obinyan
Ranch Hand
Joined: Aug 31, 2010
Posts: 394
|
|
Tommy Delson wrote:Sound like you're ready for the Final SCJP Exam....go for it if you're ready!
Everybody tells me that... ...Thanks for the beerchug and motivation! I sincerely think I am ready, funny enough most people think I have it already... I will give it a try in a few weeks from now, lets see how it goes...Wish me luck...
Regards
Ikpefua.
|
 |
Tommy Delson
Ranch Hand
Joined: Apr 13, 2011
Posts: 206
|
|
Ikpefua Jacob-Obinyan wrote:
Tommy Delson wrote:Sound like you're ready for the Final SCJP Exam....go for it if you're ready!
Everybody tells me that...  ...Thanks for the beerchug and motivation! I sincerely think I am ready, funny enough most people think I have it already... I will give it a try in a few weeks from now, lets see how it goes...Wish me luck...
Regards
Ikpefua.
Good luck and let us know how it goes...
|
 |
 |
|
|
subject: Static members | Inheritance
|
|
|