Inheritance in Java

Inheritance

class Hamster extends Rodent {
  String name; // Hamsters are pets 
	
  public Hamster(String name, float weight) {
      super(weight);
      this.name=name; 
  }

  /** Once a year */
  public age() {
      age++;
      if (alive)
        weight = weight * 1.2; // Fed too much
      if (weight>5)
        alive=false;
  }

  public declaw() {
      declawed=true;
  }
}
Next | Previous