Inheritance vs Static in Java

后端 未结 6 1887
温柔的废话
温柔的废话 2020-12-06 15:17

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

6条回答
  •  北海茫月
    2020-12-06 16:06

    For method invocation using inheritance to take place, you need to have one instance of the class.

    Since static method do not have an instance, the method definition is attached to the class it self ( no dynamic dispatch )

    That's more or less the rationale in my own words.

    It is more a technical problem ( with the implementation ) than a language feature.

    As for:

    Is Inheriting Static methods a good programming practise ?

    No, it is not. This is hard specially when you come from an structured programming language, eventually it would make sense.

    I don't really use much static methods in first place.

提交回复
热议问题