class Animal { public void animalSound() { System.out.println("The animal makes a sound"); } } class Cat extends Animal { public void animalSound() { System.out.println("The cat says: meow!"); } } class Dog extends Animal { public void animalSound() { System.out.println("The dog says: woof!"); } } class Cow extends Animal { public void animalSound() { System.out.println("The cow says: moo!"); } } class Main { public static void main(String[] args) { Animal myAnimal = new Animal(); // Create a Animal object Animal myCat = new Cat(); // Create a Cat object Animal myDog = new Dog(); // Create a Dog object Animal myCow = new Cow(); // Create a Cow object myAnimal.animalSound(); myCat.animalSound(); myDog.animalSound(); myCow.animalSound(); } }
Cùng nhau học tập, khám phá các kiến thức nền tảng về Lập trình web, mobile, database nhé.
Nền tảng kiến thức - Hành trang tới tương lai hân hạnh phục vụ Quý khách!
Khám phá, trải nghiệm ngay
Vui lòng đăng nhập để gởi bình luận!
Đăng nhậpChưa có bình luận nào!