- package ch79;
- public class ch79 {
- public static void main(String[] args) {
- Human h1=new Human("湯尼",35,70);
- h1.showProfile();
- h1.eat(0.85);
- h1.showProfile();
- h1.swim(1500);
- h1.sing("張漢仁");
- h1.takeCare();
- }
- }
- abstract class Animal
- {
- int age;
- double w;
- Animal(int age,double w)
- {
- this.age=age;
- this.w=w;
- }
- abstract void eat(double x);
- abstract void showProfile();
- }
- interface Swimmer
- {
- String Level="專業及";
- void swim(double x);
- }
- interface Singer
- {
- String Level="專業及";
- }
- interface Father
- {
- String Level="新手及";
- void takeCare();
- }
- class Human extends Animal
- {
- String name;
- Human(String name,int age,double w)
- {
- super(age,w);
- this.name=name;
- }
- void eat(double x)
- {
- System.out.println(name+"咕嚕咕嚕吃下了"+x+"公斤的食物.");
- w+=x;
- }
- void showProfile()
- {
- System.out.println(name+"今年幾歲,體重"+w+"公斤.");
- }
- public void swim(double x)
- {
- System.out.println(name+"以"+Swimmer.Level+"水準,刷刷刷快速游了"+x+"公尺");
-
- }
- public void sing(String song)
- {
- System.out.println(name+"以"+Singer.Level+"水準,唱了首"+song+".");
- }
- public void takeCare()
- {
- System.out.println(name+"以"+Father.Level+"水準,開始扮演父親的角色,照顧小孩");
- }
-
-
- }
複製代碼 |