面向对象程序设计——第六章接口课后作业

这篇博客探讨了如何在面向对象程序设计中,基于第六章关于接口的内容,对第三题的功能进行扩展,并详细阐述了如何运用接口思想对电子宠物系统类结构进行重构。
摘要由CSDN通过智能技术生成

1.在第三题的进行功能扩展。

package come.job.dome;
/**
 * 
 * @author 宠物类
 *
 */
public class Store {
	public static Animal get(int choice) {
		if(choice==1) { //狗狗
			return new Dog();
		}else if(choice==2) { //猫
			return new Cat();
		}else {
			return new Pig(); //猪
		}
	}
}
package come.job.dome;
/**
 * 
 * @author 狗狗
 *
 */
public class Dog implements Animal {
	public void show() {
		System.out.println("W W!");
	}
}
package come.job.dome;
/**
 * 
 * @author 猫
 *
 */
public class Cat implements Animal {
	public void show() {
		System.out.println("M M!");
	}
}
package come.job.dome;
/**
 * 
 * @author 猪
 *
 */
public class Pig implements Animal{
	public void show() {
		System.out.println("猪叫");
	}
}
package come.job.dome;
/**
 * 
 * @author 接口
 *
 */
public interface Animal {
	void show();
}
package come.job.dome;

import java.util.Scanner;
/**
 * 
 * @author 测试类
 *
 */
public class AnimalTes
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值