Example #1
0
  // The main method is the point of entry into the program...
  public static void main(String[] args) {

    Animal a = new Animal();
    System.out.println(a.numberOfLegs);
    System.out.println(a.hasWings);
    a.talk();
    // a.fly(); method doesn't exist in superclass

    Bird b = new Bird();
    System.out.println(b.numberOfLegs);
    System.out.println(b.hasWings);
    System.out.println(b.canFly);
    // System.out.println(b.numberOfKills); variable doesn't exist in superclass
    b.talk();
    // b.attack();  method doesn't exist in superclass

    Eagle e = new Eagle();
    // System.out.println(e.numberOfKills); variable is private
    System.out.println(e.numberOfLegs);
    System.out.println(e.hasWings);
    e.talk();
    e.attack();

    a = b;
    a.talk();
    // a.fly();

    b = a;
    b.talk();
    b.fly();
  }
 public void fly(Eagle eagle) {
   System.out.println("i fly on " + eagle.getName());
 }