示例#1
1
 public static void main(String[] args) {
   Breeder breeder = new Breeder();
   Dog dog = breeder.breedDog();
   dog.bark();
   dog.fetch();
   dog.bark();
   dog.fetch();
 }
示例#2
0
  public static void main(String[] args) {
    Dog one = new Dog();
    one.size = 70;
    Dog two = new Dog();
    two.size = 8;
    Dog three = new Dog();
    three.size = 35;

    one.bark();
    two.bark();
    three.bark();
  }
示例#3
0
 public static void main(String[] args) {
   Animal a = new Animal();
   Animal b = new Dog(); // b 是Animal 的一个引用  不用调用父类没有的方法 要想调用自己的方法 则需要创建本类的对象
   a.move();
   b.move();
   Dog dog = new Dog();
   dog.bark();
 }
示例#4
0
  public static void main(String[] args) {
    Dog dog1 = new Dog();
    dog1.bark();
    dog1.name = "Bart";

    Dog[] myDogs = new Dog[3];

    myDogs[0] = new Dog();
    myDogs[1] = new Dog();
    myDogs[2] = dog1;

    myDogs[0].name = "Fred";
    myDogs[1].name = "Marge";

    System.out.println("last dog's name is ");
    System.out.println(myDogs[2].name);

    int x = 0;

    while (x < myDogs.length) {
      myDogs[x].bark();
      x++;
    }
  }
示例#5
0
 public static void main(String[] args) {
   Dog d = new Dog();
   d.size = 40;
   d.bark();
 }
 public static void main(String[] args) {
   Dog[] dogs = {new Dog("Elyse", 3), new Dog("Sture", 9), new Dog("Artemesios", 15)};
   Dog maxDog = (Dog) max(dogs);
   maxDog.bark();
 }