【代码6-1】
class Circle (1)
private (2) pxc;
public Circle()pxc=new (3) ;
public void display()
pxc. (4) ;
【代码6-2】
public class Factory
public (5) getShapeInstance(int type) //生成特定类实例
switch(type)
case 0: return new Point ( );
case 1: return new Rectangle ( ) ;
case 2: return new Line ( ) ;
case 3: return new Circle ( ) ;
default: return null;
public class App
public static void main (String argv[] )
if (argv. length != l)
System. out.println ("error parameters !");
return;
inttype= (new Integer (argv[0])) .intValue (
Factory factory = new Factory ( ) ;
Shape s;
s=factory, (6)
if (s==null)
System.out.println ( "Error get instance !" )
return;
s.display () ;
return;