// Written by: Darren Gates & Ray Klefstad // Date: January 2000 // School: U.C. Irvine import java.awt.*; import java.applet.*; public class InheritanceExample extends Applet { public void init() { TextArea birds = new TextArea(5, 35); add(birds); Bird newBird = new Bird("Tweetie", 8); Woodpecker newWoodpecker = new Woodpecker("Woody", 12, "red"); // concatenate all the Bird info & display it String newBirdInfo, newWoodpeckerInfo; newBirdInfo = newBird.getName() + " weighs " + newBird.getWeight() + " ounces."; newWoodpeckerInfo = newWoodpecker.getName() + " weighs " + newWoodpecker.getWeight() + " ounces, and is " + newWoodpecker.getColor() + "."; birds.setText(newBirdInfo + "\n" + newWoodpeckerInfo); } } class Bird { protected String name; protected int weight; public Bird(String newName, int newWeight) { name = newName; weight = newWeight; } public int getWeight() { return weight; } public String getName() { return name; } } class Woodpecker extends Bird { protected String color; public Woodpecker(String newName, int newWeight, String newColor) { super(newName, newWeight); // calls Bird class constructor color = newColor; } public String getColor() { return color; } }