3.28
这个题并没有什么意思啊
就当熟练了一下接口吧。
继承一个接口就是要实现它里边的方法。
/**
* Your object will be instantiated and called as such:
* ToyFactory tf = new ToyFactory();
* Toy toy = tf.getToy(type);
* toy.talk();
*/
interface Toy {
void talk();
}
class Dog implements Toy {
public void talk(){// Write your code here
System.out.print("Wow");
}
}
class Cat implements Toy {
public void talk(){// Write your code here
System.out.print("Meow");
}
}
public class ToyFactory {
/**
* @param type a string
* @return Get object of the type
*/
public Toy getToy(String type) {
if(type.equals("Dog")){
return new Dog();
}
if(type.equals("Cat")){
return new Cat();
}
return null;
}
}