package zuoye;
public class test {
public static void main(String[] args) {
Cat19 cat=new Cat19();
Dog19 dog=new Dog19();
Rabbit19 rabbit=new Rabbit19();
AnimalFactory19 hh=new AnimalFactory19();
hh.enter(dog);
hh.enter(cat);
hh.enter(rabbit);
}
}
package zuoye;
public class Rabbit19 extends Animal19{
public Rabbit19() {
name="兔子";
}
public void makeSound() {
System.out.println("呲呲呲!");
}
}
package zuoye;
public class Dog19 extends Animal19{
public Dog19() {
name="狗";
}
public void makeSound() {
System.out.println("汪汪汪!");
}
}
package zuoye;
public class Cat19 extends Animal19{
public Cat19() {
name="猫";
}
public void makeSound() {
System.out.println("喵喵喵!");
}
}
package zuoye;
public class AnimalFactory19 {
public Animal19 act;
public void enter(Animal19 act) {
this.act=act;
System.out.println(act.getName()+" 它的叫声:");
act.makeSound();
}
}
package zuoye;
public class Animal19 {
protected String name;
int age;
public void makeSound() {
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
期末作业呵呵呵呵呵呵呵呵
最新推荐文章于 2024-11-15 18:38:47 发布