• Post Reply Bookmark Topic Watch Topic
  • New Topic

Inheritance of Static members  RSS feed

 
Ranch Hand
Posts: 30
Eclipse IDE Hibernate 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!