Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Inheritance of Static members

 
Ranch Hand
Posts: 30
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Let me tell you a story about a man named Jed. He made this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic