试图理解Java中多态的基础知识.

SyC*_*ode 0 java polymorphism

有人可以告诉我,关键字'extends'是否必须是超类方法的子类的使用(在语法中).

pet*_*rov 7

该单词extends用于表示整个类,该类是另一个类的子类.它与子类是否覆盖某些方法无关,这完全取决于子类.子类可以决定覆盖超类的任何方法,部分方法或全部方法.子类可以仅覆盖未final在超类中标记的方法.

这是一个有点微不足道的例子:

class A {
    // This is the super-class.
    public void myMethod() {...};
}

class B extends A { 
    // This extends above says: B is sub-class of A.
    // So this class B is the sub-class of A.
    // You can override methods of A here, like this
    public void myMethod() {...};
    // but you're not required to override them. 
}
Run Code Online (Sandbox Code Playgroud)