Why doesn't Java allow overriding of static methods?

后端 未结 22 3098
谎友^
谎友^ 2020-11-21 05:49

Why is it not possible to override static methods?

If possible, please use an example.

22条回答
  •  离开以前
    2020-11-21 06:24

    What good will it do to override static methods. You cannot call static methods through an instance.

    MyClass.static1()
    MySubClass.static1()   // If you overrode, you have to call it through MySubClass anyway.
    

    EDIT : It appears that through an unfortunate oversight in language design, you can call static methods through an instance. Generally nobody does that. My bad.

提交回复
热议问题