<a href="http://faq.javaranch.com/java/UseCodeTags" target="_blank">Use Code Tags!!</a>
SCJP, SCWCD.
|Asking Good Questions|
SCJP, SCWCD.
|Asking Good Questions|
static methods can be inherrited.
constructors are called automatically at the time of the creation of the instance of the class.
We dont need any instance of the class to call any static method or static variable.
SCJP, SCWCD.
|Asking Good Questions|
Constructors, static initializers, and instance initializers are not members and therefore are not inherited.
If a class declares a static method, then the declaration of that method is said to hide any and all methods with the same signature in the superclasses and superinterfaces of the class that would otherwise be accessible to code in the class.
SCJP, SCWCD.
|Asking Good Questions|
Originally posted by myself:
In that case it remains as a static method of the superclass.
Originally posted by bittoo garg:
Amit, you are talking about static method when they are redefine by child class. In that case static methods are not inherited.
But what if, child class decides not to redefine the static method ?
SCJP, SCWCD.
|Asking Good Questions|
One more thing, I think you are confused with static methods because you are using an object to invoke it.
In your code the "s.display();" is not the proper way to call a static method, seeing code like this one may get an impression that th object s is used to call display() but the fact is s is replaced by subclass before display() can be called.
Amit Ghorpade already has. He has told you exactly how static members behave in Java.Originally posted by bittoo garg:
Hi,
Can somebody conclude this thread.
Originally posted by Campbell Ritchie:
Amit Ghorpade already has. He has told you exactly how static members behave in Java.
SCJP, SCWCD.
|Asking Good Questions|
If you carefully read my above post then you can see that it says that the static method is accessible to the child. This is only because of the IS-A relationship fred said in that little thread.
So maybe the static methods are in fact inherited after all, but as you correctly say, they cannot be overridden. There are examples in Effective Java and Java Puzzlers (more details on this Ranch page) where there are confusing problems caused by confusion between overriding and hiding static methods.The members of a class type (�8.2) are classes (�8.5, �9.5), interfaces (�8.5, �9.5), fields (�8.3, �9.3, �10.7), and methods (�8.4, �9.4). Members are either declared in the type, or inherited because they are accessible members of a superclass or superinterface which are neither private nor hidden nor overridden (�8.4.8).
Originally posted by Campbell Ritchie:
Amit, I suspect you and I have both made the same mistake.
SCJP, SCWCD.
|Asking Good Questions|
I want my playground back. Here, I'll give you this tiny ad for it:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|