I dont quite understand why Static methods can be inherited in Java ?
Inheritance is like inheriting from the base class AND Static belongs to the Class and not Obje
I dont quite understand why Static methods can be inherited in Java ?
The short answer is that statics are NOT inherited in Java. Rather, the static members declared in a class are (subject to "access" restrictions) directly visible in the namespace of derived classes, unless they "hidden" by declarations in the derived class.
So if the Static belongs to the Class only why does it trickle down to the derived class ? Shouldn't it just stay with the Class in which it was defined ?
Trickle down is not a technical term. But that's not what is happening anyway. The static members of the class are not members of the derived class.
Is Inheriting Static methods a good programming practise ?
You cannot stop it happening!
Just FYI, here are some "good practice" issues related to statics:
Mutable static attributes should be private, and preferably recast as Singleton objects.
A lot of statics members (methods or attributes) or even Singletons, can be a sign of a bad design. It is certainly not "the object-oriented way".
In some kinds of application (e.g. web apps), even Singleton objects are problematic.
It is bad practice to refer to a static method a obj.someStaticMethod() or this.someStaticMethod(). Either qualify the static name with the class name, or refer to it without qualification.
It is (arguably) better to qualify a reference to a static in superclass; e.g. in SubClass, refer to SuperClass.someStaticMethod() rather than someStaticMethod(). (But the downside is that the code is more verbose. This falls under the same banner as the pros and cons of importing.)
static final constants should be declared with all-caps names.