// Superclass
class Vehicle {
  protected int year;                // Vehicle attribute
  Vehicle( int y ) { year = y; }     // Vehicle constructor
  protected void honk( ) {           // Vehicle method
    System.out.print( "Honk! " );
  }
}
// Subclass
class Car extends Vehicle {
  public static String brand;        // Car attribute
  public static void main( String[ ] args ) {
    // Assign a brand value.
    brand = args[0];
    // Create a myCar object.
    Vehicle myCar = new Car( args[1] );
    // Call the honk( ) method (from the Vehicle class) on the myCar object.
    myCar.honk( );
    // Display the values of the brand & year attributes
    System.out.print( myCar.brand + " " + myCar.year );
  }
  // Constructor
  Car( String year ) { super( Integer.parseInt( year ) ); }
}
    
    |