ihongjun@ihongjun-ui-iMac:~/Funny/java/Pure$ tree
.
├── bin
└── src
└── Goose.java
2 directories, 1 file
ihongjun@ihongjun-ui-iMac:~/Funny/java/Pure$ cat src/Goose.java
interface Flyable {
public String fly();
}
abstract class Bird implements Flyable {
public String fly() {
return "A bird fly";
}
}
class Owl extends Bird { }
class Chicken extends Bird {
public String fly() {
return "Chicken can't fly";
}
}
public class Goose extends Bird {
public static void main(String[] args) {
Flyable[] f = new Flyable[3];
f[0] = new Chicken();
f[1] = new Owl();
f[2] = new Goose();
for(int x = 0; x < 3; x++) {
System.out.println(f[x].fly() + " " + f[x].getClass());
}
}
}
ihongjun@ihongjun-ui-iMac:~/Funny/java/Pure$ javac -d bin src/Goose.java
ihongjun@ihongjun-ui-iMac:~/Funny/java/Pure$ java -cp bin Goose
Chicken can't fly class Chicken
A bird fly class Owl
A bird fly class Goose
ihongjun@ihongjun-ui-iMac:~/Funny/java/Pure$ tree
.
├── bin
│ ├── Bird.class
│ ├── Chicken.class
│ ├── Flyable.class
│ ├── Goose.class
│ └── Owl.class
└── src
└── Goose.java
2 directories, 6 files