📄 testhorse.java
字号:
package CF;
abstract class Horse {
String color;
int age;
String getcolor() {
return color;
}
int getage() {
return age;
}
abstract String horsefood();
}
class WhiteHorse extends Horse {
String food = "grass";
public WhiteHorse(String str, int i) {
color = str;
age = i;
}
String horsefood() {
return food;
}
}
class RedHorse extends Horse {
String food = "meat";
public RedHorse(String str, int i) {
color = str;
age = i;
}
String horsefood() {
return food;
}
}
public class TestHorse {
Horse getType(){
WhiteHorse c = new WhiteHorse("White", 103);
return c;
}
public static void main(String[] args) {
WhiteHorse c = new WhiteHorse("White", 103);
System.out.println(c.getcolor());
System.out.println(c.getage());
System.out.println(c.horsefood());
RedHorse r = new RedHorse("red", 3);
System.out.println(r.getcolor());
System.out.println(r.getage());
System.out.println(r.horsefood());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -