コード例 #1
0
ファイル: AnimalTest.java プロジェクト: JWeel/AppStudio
  // 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();
  }
コード例 #2
0
ファイル: CatDog.java プロジェクト: thomasalvatran/ctest-hp
  public static void main(String[] args) {

    Collection<Animal> animals = new ArrayList<Animal>();
    animals.add(new Cat("Cat", "Meow Meow"));
    animals.add(new Dog("Dog", "Arf Arf Arf"));
    animals.add(new Dog("Dog", "Arffff Arf Arf"));
    for (Animal a : animals) {
      System.out.println(a.getName() + " " + a.talk());
    }
    //				Cat a = new Cat("Cat","Meow Meow");
    //				Dog b = new Dog("Dog","Arf Arf Arf");
    //				System.out.println(a.getName()+" "+a.talk() );
    //				System.out.println(b.getName()+" "+b.talk() );
  }