Why do we say that a static method in Java is not a virtual method?

前端 未结 5 1751
北恋
北恋 2021-01-05 06:58

In object-oriented paradigm, a virtual function or virtual method is a function or method whose behavior can be overridden within an inheriting class by a f

5条回答
  •  说谎
    说谎 (楼主)
    2021-01-05 07:14

    It's simple, a static method cannot be overridden by an inheriting class, since it's not inherited. So it's not virtual.

    What you call "overriding a static method" is actually only defining another static method on another class. It'll only "hide" (and that's actually a much stronger word than what'd be actually true there) the other one, not override it.

提交回复
热议问题