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