
interface ImmutablePerson
{
    void print( );
}

class Person implements ImmutablePerson
{
    public Person( String n, int a )
    {
        name = n; age = a;
    }
    
    public void print( )
    {
        System.out.print( name + " " + age );
    }
    
    private String name;
    private int age;
}

class Student extends Person
{
    public Student( String n, int a, double g )
    {
        super( n, a );
        gpa = g;
    }
    
    public void print( )
    {
        super.print( );
        System.out.print( " " + gpa );
    }
    
    private double gpa;
}

class Employee extends Person
{
    public Employee( String n, int a, double s )
    {
        super( n, a );
        salary = s;
    }
    
    public void print( )
    {
        super.print( );
        System.out.print( " " + salary );
    }
    
    private double salary;
}

class DynamicDemo
{
    public static void printAll( ImmutablePerson[] p )
    {
        for( int i = 0; i < p.length; i++ )
        {
            if( p[ i ] != null )
            {
                System.out.print( "[" + i + "] " );
                p[i].print( );
                System.out.println( );
            }
        }
    }
    
    public static void main( String [] args )
    {
        Person [] p = new Person[ 4 ];
        
        p[0] = new Person( "joe", 25 );
        p[1] = new Student( "jill", 27, 4.0 );
        p[3] = new Employee( "bob", 29, 3.8 );
        
        printAll( p );
    }
}
