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