📄 eatabledemo.java
字号:
interface Eatable {
public void howToEat();
}
class Animal implements Eatable {
public void howToEat() {
System.out.println("Animal eatable");
}
}
class Tiger extends Animal {
public void howToEat() {
System.out.println("Tiger eatable");
}
public String toString() {
return "Tiger";
}
}
class Elephant extends Animal {
public void howToEat() {
System.out.println("Elephant eatable");
}
public String toString() {
return "Elephant";
}
}
class Chilken extends Animal {
public void howToEat() {
System.out.println("Chilken is eatable");
}
public String toString() {
return "Chilken";
}
}
class Friut implements Eatable {
public void howToEat() {
System.out.println("Friut is eatable");
}
}
class Apple extends Friut {
public void howToEat() {
System.out.println("Apple is eatable");
}
public String toString() {
return "Apple";
}
}
class Orange extends Friut {
public void howTeat() {
System.out.println("Orange is eatable");
}
public String toString() {
return "Orange";
}
}
public class EatableDemo {
public static void main(String[] args) {
Tiger t = new Tiger();
Chilken c = new Chilken();
Apple a = new Apple();
Orange o = new Orange();
showOb(t);
showOb(c);
showOb(a);
showOb(o);
}
public static void showOb(Object object) {
System.out.println(object);
if(object instanceof Eatable)
((Eatable)object).howToEat();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -