testhorse.java

来自「所学课程的编码。java的基础例子。可以练习java通过这些例子。。」· Java 代码 · 共 61 行

JAVA
61
字号
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 + =
减小字号Ctrl + -
显示快捷键?