标签:demo system null col span public rri code ring
interface Fruit{ public void eat(); } class Apple implements Fruit{ @Override public void eat() { System.out.println("吃苹果"); } } class Cherry implements Fruit{ @Override public void eat() { System.out.println("吃樱桃"); } } class Factory{ //工厂 public static Fruit getInstance(String className){ if ("apple".equals(className)){ return new Apple(); }else if ("cherry".equals(className)){ return new Cherry(); }else{ return null; } } } public class FactoryDemo { public static void main(String[] args){ Fruit f = Factory.getInstance(args[0]); f.eat(); } }
标签:demo system null col span public rri code ring
原文地址:https://www.cnblogs.com/LoveGdx/p/11904397.html