续写这段代码package animal; public abstract class Animal { private String name; public Animal(String name) { this.name = name; } public String getName() { return name; } public void setName(String name) { this.name = name; } public abstract void makeSound();
时间: 2024-04-11 11:32:58 浏览: 108
labview-txt.rar_labview txt 续写_labview 存成txt_labview文件保存_site:ww
public class Cat extends Animal {
private int age;
public Cat(String name, int age) {
super(name);
this.age = age;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
@Override
public void makeSound() {
System.out.println("Meow");
}
}
public class Dog extends Animal {
private String breed;
public Dog(String name, String breed) {
super(name);
this.breed = breed;
}
public String getBreed() {
return breed;
}
public void setBreed(String breed) {
this.breed = breed;
}
@Override
public void makeSound() {
System.out.println("Woof");
}
}
public class Elephant extends Animal {
private int weight;
public Elephant(String name, int weight) {
super(name);
this.weight = weight;
}
public int getWeight() {
return weight;
}
public void setWeight(int weight) {
this.weight = weight;
}
@Override
***
阅读全文