interface product{
public void car(); } interface factory{
public product createcar(); } class AmaFactory implements factory{
@Override public product createcar() {
return new Amacar(); } } class YadiFactory implements factory{
@Override public product createcar() {
return new Yadicar(); } } class Amacar implements product{
@Override public void car() {
System.out.println("爱玛电动车成功生产啦"); } } class Yadicar implements product{
@Override public void car() {
System.out.println("雅迪电动车成功生产啦"); } } public class Main {
public static void main(String[] args) {
// System.out.println("Hello World!"); AmaFactory am =new AmaFactory(); am.createcar().car(); System.out.println("====== 分割线 ========="); YadiFactory yadi=new YadiFactory(); yadi.createcar().car(); } }