- public class Ch72
- {
- 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 a,double w)
- {
- age = a;
- this.w = w;
- }
-
- abstract void eat(double x);
- abstract void showProfile();
-
- }
- interface Swimmer
- {
- String LEVEL = "專業級";
- void swim(double x);
- }
- interface Singer
- {
- String LEVEL = "專業級";
- void sing(String song);
- }
- interface Father
- {
- String LEVEL = "新手級";
- void takeCare();
- }
- class Human extends Animal implements Swimmer,Singer,Father
- {
- String name;
- Human(String n ,int a, double w)
- {
- super(a, w);
- name = n;
- }
- @Override
- public void takeCare() {
- System.out.println(name+"以"+Father.LEVEL+"開始扮演父親的角色,照顧小孩");
-
- }
- @Override
- public void sing(String song) {
- System.out.println(name+"以"+Singer.LEVEL+"的水準,唱了一首"+song);
-
- }
- @Override
- public void swim(double x) {
- System.out.println(name+"以"+Swimmer.LEVEL+"的水準,快速地游了"+x+"公尺");
-
- }
- @Override
- void eat(double x) {
- System.out.println(name+"快速地吃下了"+x+"公斤的食物");
- w+=x;
- }
- @Override
- void showProfile() {
- System.out.println(name+"今年"+age+"歲,體重"+w+"公斤");
-
- }
-
- }
複製代碼 |