HomeDigital EditionSys-Con RadioSearch Java Cd
Advanced Java AWT Book Reviews/Excerpts Client Server Corba Editorials Embedded Java Enterprise Java IDE's Industry Watch Integration Interviews Java Applet Java & Databases Java & Web Services Java Fundamentals Java Native Interface Java Servlets Java Beans J2ME Libraries .NET Object Orientation Observations/IMHO Product Reviews Scalability & Performance Security Server Side Source Code Straight Talking Swing Threads Using Java with others Wireless XML
 

"Dynamic Tools: Evolutive Java Applications"
Vol. 7, Issue 1, p. 70

	


Listing 1: Definitions used in the example


  class Person
{
    public Person (String n, int a)
    {
       name=n; age=a; allPersons.add(this);
    };

    public static Enumeration getAll()
    {
       return allPersons.elements();
    };

    public String getName()
    {
       return name;
    } ;

    protected static Vector allPersons =
                                     new Vector();
    protected String name ;
    protected int age ;
}

public class Man extends Person
{
    public Man (String n, int a) {super(n, a);}
}

public class Woman extends Person
{
    public Woman (String n, int a) {super(n, a);}
}

public interface Print
{
    void toStandardOutput() ;
}

Listing 2: Full solution public class


PrintAllPersons
{
    public static void main (String [] arg)
    {
       Enumeration e = Person.getAll();
       while (e.hasMoreElements())
       {
          Print d = (Print) e.nextElement() ;
          d.toStandardOutput () ;
        }
    }
}

abstract class DA_Person
{
    public int age;
}

public abstract class DI_Person__Print
implements Print
{
    public void toStandardOutput()
    {
       Person p = (Person) (Object) this ;
       System.out.println (p.getName()) ;

       DA_Person pp = (DA_Person) (Object) this ;
       System.out.println (pp.age) ;
    }
}

  
 
 

All Rights Reserved
Copyright ©  2004 SYS-CON Media, Inc.
  E-mail: [email protected]

Java and Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. SYS-CON Publications, Inc. is independent of Sun Microsystems, Inc.