• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Static members | Inheritance

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 394
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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....



 
Tommy Delson
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
https://coderanch.com/t/368681/java/java/statics-inherited
 
Ikpefua Jacob-Obinyan
Ranch Hand
Posts: 394
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 206
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 394
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 206
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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...
 
If we don't do the shopping, we won't have anything for dinner. And I've invited this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic