期末作业呵呵呵呵呵呵呵呵

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;
}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值