Package net.util;/** * @ Project Name: spring2.5 * @ Pack Name: Net.util * @ file name: Factorydemo.java * @ Date: June, 4:37:02 PM * @ Note: Factory mode * @ By: Apple */public class Factorydemo {/*** @param args*/public static void Main (string[] args) {//TODO auto-generated Metho D stubcar c=factory.getcarinstance ("Banz"); if (c!=null) {c.run (); C.stop ();} ELSE{SYSTEM.OUT.PRINTLN ("cannot be created");}}} Class Factory{public static car Getcarinstance (String type) {car c=null;try {c= (CAR) class.forname ("Net.util.") +type). newinstance ();} catch (Instantiationexception e) {//TODO auto-generated catch Blocke.printstacktrace ();} catch (Illegalaccessexception e) {//Todo auto-generated catch Blocke.printstacktrace ();} catch (ClassNotFoundException e) {//Todo auto-generated catch Blocke.printstacktrace ();} return c;}} Interface car{public void Run ();p ublic void Stop (); Class Banz implements Car{public void Run () {//TODO auto-generated method StubSystem.out.println ("Banz Run");} public void Stop () {//TODO auto-generated method StubSystem.out.println ("BaNZ stop ");}} Class Ford implements Car{public void Run () {//TODO auto-generated method StubSystem.out.println ("Ford Run");} public void Stop () {//TODO auto-generated method StubSystem.out.println ("Ford Stop");}}