執行 ❯
獲取您
自己的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 } }
動物發出聲音
狗說:汪汪