package day15;
interface Fruit {
public void info();
}
class Apple implements Fruit {
public void info() {
System.out.println("苹果");
};
}
class Orange implements Fruit {
@Override
public void info() {
// TODO 自动生成的方法存根
System.out.println("橘子");
}
}
class FruitFactory {
public static Fruit getInstance(String type) throws ClassNotFoundException,
InstantiationException, IllegalAccessException {
Class class1 = Class.forName(type);
Fruit f = (Fruit) class1.newInstance();
if (f != null) {
return f;
} else {
return null;
}
}
}
public class FactoryModel02 {
public static void main(String[] args) throws ClassNotFoundException,
InstantiationException, IllegalAccessException {
Fruit fff = FruitFactory.getInstance("day15.Orange");
fff.info();
}
}
interface Fruit {
public void info();
}
class Apple implements Fruit {
public void info() {
System.out.println("苹果");
};
}
class Orange implements Fruit {
@Override
public void info() {
// TODO 自动生成的方法存根
System.out.println("橘子");
}
}
class FruitFactory {
public static Fruit getInstance(String type) throws ClassNotFoundException,
InstantiationException, IllegalAccessException {
Class class1 = Class.forName(type);
Fruit f = (Fruit) class1.newInstance();
if (f != null) {
return f;
} else {
return null;
}
}
}
public class FactoryModel02 {
public static void main(String[] args) throws ClassNotFoundException,
InstantiationException, IllegalAccessException {
Fruit fff = FruitFactory.getInstance("day15.Orange");
fff.info();
}
}