- public class A {
- public static void main(String[] args) {
- Human h=new Human("湯尼", 35, 70);
- h.showProfile();
- h.eat(0.85);
- h.showProfile();
- h.swim(1500);
- h.sing("新不了情");
- h.takeCare();
- h.fly();
- }
- }
- 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();
- }
- interface Genius extends Swimmer,Singer, Father
- {
- String LEVEL="大神級";
- void fly();
- }
- class Human extends Animal implements Genius
- {
- String name;
- Human(String n, int a, double w)
- {
- super(a, w);
- name=n;
- }
- @Override
- void eat(double x) {
- System.out.println(name+"咕嚕咕嚕吃下"+x+"公斤的食物。");
- w=w+x;
- }
- @Override
- void showProfile() {
- System.out.println(name+"今年"+age+"歲,體重"+w+"公斤。");
- }
- @Override
- public void swim(double x) {
- System.out.println(name+"以"+Swimmer.LEVEl+"水準,刷刷刷快速地遊了"+x+"公尺。");
- }
- @Override
- public void sing(String song) {
- System.out.println(name+"以"+Singer.LEVEL+"水準,唱了一首"+song+"。");
- }
- @Override
- public void takeCare() {
- System.out.println(name+"以"+Father.LEVEL+"水準,開始扮演父親的角色,照顧小孩。");
- }
- @Override
- public void fly() {
- System.out.println(name+"以"+Genius.LEVEL+"水準,快速揮動兩片扇子,飛了起來!");
- }
- }
複製代碼 |