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

前端 未结 5 1800
北恋
北恋 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

    An abstract class in Java is nothing but the pure virtual method equivalent to C++.

    A class is not a method. An abstract class doesn't have to have "virtual" or abstract methods, or even any methods.

    Something C++ developers put down Java features as just like C++ renamed without understanding the differences. ;)

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

    Not sure who says this, but static methods are not polymorphic.

    Even if we can override the static method

    We can't, you can only hide or overload a static method.

    Whether you use the class or sub-class or instance to invoke a static method the actual class or instance is ignored. e.g. you can do

    ((Thread) null).yield();
    

提交回复
热议问题