- 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();
- }
- }
- 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
- void eat(double x) {
- System.out.println(name+"咕嚕咕嚕吃下了"+x+"公斤的食物。");
- w=w+x;
- }
- @Override
- void showProfile() {
- System.out.println(name+"今年"+age+"歲,體重"+w+"公斤。");
-
- }
- @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+"公尺。");
- }
- }
複製代碼 |