• 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

Inheritance of Static members

 
Ranch Hand
Posts: 30
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello guys!! I have heard lots of people saying that static members are not inherited and also that such members are not overridden but right now I am stuck with an example that is complelling me that static members are inherited.


When running on netbeans ide with jdk 1.7 I have been shooted with below error-:


run:
Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - double_val() in javaapplication3.JavaApplication3 cannot override double_val() in javaapplication3.cls
attempting to assign weaker access privileges; was public
at javaapplication3.JavaApplication3.double_val(JavaApplication3.java:23)
at javaapplication3.JavaApplication3.main(JavaApplication3.java:29)
Java Result: 1
BUILD SUCCESSFUL (total time: 2 seconds)


Over here if there were no inheritance of static method then this error message would not have thrown.


I think this error comes only when something gets overriden in a derived class that implies both overriding and inheritance of base class static members .Is this my correct understanding or I am missing something.

Thanks and Regards!!
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Gautam Bhalla wrote:Hello guys!! I have heard lots of people saying that static members are not inherited and also that such members are not overridden



They can be inherited, but they cannot be overridden. When a static child member has the same name (and for methods, signature) as an accessible parent member, the child member hides the inherited parent member.
 
What are your superhero powers? Go ahead and try them on this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic