animal.java
来自「关于java面向对象系统分析方面的课件」· Java 代码 · 共 44 行
JAVA
44 行
package s2Java.sg.ch03.homework;
public interface Animal {
void voice();
}
class Dog implements Animal {
public void voice() {
System.out.println("W W!");
}
}
class Cat implements Animal {
public void voice() {
System.out.println("M M!");
}
}
class Store {
public static Animal get( String choice ) {
if ( choice.equalsIgnoreCase( "dog" )) {
return new Dog();
} else {
return new Cat();
}
}
}
class Pig implements Animal {
public void voice() {
System.out.println("O O!");
}
}
class Store2{
public static Animal get( String choice ) {
if ( choice.equalsIgnoreCase( "dog" )) {
return new Dog();
} else if ( choice.equalsIgnoreCase( "pig" )) {
return new Pig();
} else
return new Cat();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?