- public class Morris {
- public static void main(String[] args) {
- human hu1 = new human("湯尼", 35, 70);
- hu1.showProfile();
- hu1.eat(0.85);
- hu1.showProfile();
- hu1.swim(1500);
- hu1.sing("新不了情");
- hu1.takeCare();
- }
- }
- abstract class animal
- {
- int age;
- double w;
- animal(int a, double w)
- {
- age = a;
- this.w = w;
- }
- abstract void showProfile();
- abstract void eat(double x);
- }
- interface swimmer
- {
- String Level = "專業級";
- void swim(double m);
- }
- interface singer
- {
- String Level = "專業級";
- void sing(String x);
- }
- interface father
- {
- String Level = "新手級";
- void takeCare();
- }
- class human extends animal implements swimmer, singer, father
- {
- String name;
- human(String name, int a, double w)
- {
- super(a, w);
- this.name = name;
- }
- public void showProfile()
- {
- System.out.println(name+"今年"+age+"歲,體重"+w+"公斤.");
- }
- public void eat(double x)
- {
- System.out.println(name+"咕嚕咕嚕吃下了"+x+"公斤的食物.");
- w+=x;
- }
- public void swim(double m)
- {
- System.out.println(name+"以"+swimmer.Level+"水準,唰唰唰快速地游了"+m+"公尺.");
- }
- public void sing(String x)
- {
- System.out.println(name+"以"+singer.Level+"水準,唱了一首"+x+".");
- }
- public void takeCare()
- {
- System.out.println(name+"以"+father.Level+"水準,開始扮演父親的角色,照顧小孩.");
- }
- }
複製代碼 |