运行 ❯
获取你自己的
Java
服务器
×
变更方向
变更主题,浅色/深色
转到 Spaces
class Animal { // Superclass (parent) public void animalSound() { System.out.println("The animal makes a sound"); } } class Dog extends Animal { // Subclass (child) public void animalSound() { super.animalSound(); // Call the superclass method System.out.println("The dog says: bow wow"); } } public class Main { public static void main(String[] args) { Animal myDog = new Dog(); // Create a Dog object myDog.animalSound(); // Call the method on the Dog object } }
该动物叫
该狗叫:汪汪