W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
class Animal { // 超类(父) public void animalSound() { System.out.println("动物发出声音"); } } class Dog extends Animal { // 子类(子) public void animalSound() { super.animalSound(); // 调用超类方法 System.out.println("狗叫:汪汪汪"); } } public class Main { public static void main(String args[]) { Animal myDog = new Dog(); // 创建 Dog 对象 myDog.animalSound(); // 调用 Dog 对象的方法 } }