- 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.0);
- h1.singProfile();
- h1.homeProfile();
- }
- }
- 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();
- }
- class Human extends Animal
- {
- String name,good,bad,song,character,thing;
- Human(String name,String good,String bad,String song,String character,String thing,int age,double w)
- {
- super(age,w);
- this.name=name;
- this.good=good;
- this.bad=bad;
- this.song=song;
- this.character=character;
- this.thing=thing;
- }
- void eat(double x)
- {
- System.out.println(name+"咕嚕咕嚕吃下了"+x+"公斤的食物.");
- w+=x;
- }
- void showProfile()
- {
- System.out.println(name+"今年幾歲,體重"+w+"公斤.");
- }
- void swim(double y)
- {
- System.out.println(name+"以"+good+"水準,刷刷刷快速的游了"+y);
- }
- void singProfile()
- {
- System.out.println(name+"以"+good+"水準,唱了一首"+song);
- }
- void homeProfile()
- {
- System.out.println(name+"以"+bad+"水準,開始扮演"+character+"的角色"+thing);
- }
-
- }
複製代碼 |