标签:apple classname nbsp demo 工厂 else cto equal out
interface Fruit(){
public void eat();
}
class Apple implements Fruit(){
public void eat(){
System.out.println("吃苹果");
}
class Orange implements Fruit(){
public void eat(){
System.out.println("吃橘子");
}
class Factory(){
public static Fruit getInstance(String className){
if("apple".equals(calssName)){
return new Apple
}else{return new Orange}}
public class TestDemo{
public static void main(String args[]){
Fruit f=Factory.getInstance("apple");
f.eat();
}}
}
标签:apple classname nbsp demo 工厂 else cto equal out
原文地址:http://www.cnblogs.com/Janet-3058/p/6754239.html