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