本帖最後由 陳志祐 於 2021-12-11 19:56 編輯
- public class Ch60 {
- public static void main(String[] args)
- {
- Family father=new Family("爸爸",40,"爬山");
- Family mother=new Family("媽媽",37,"逛街");
- Family boy=new Family("男孩",10,"打電動");
- Family girl=new Family("女孩",8,"看書");
- father.showprofile();
- mother.showprofile();
- boy.showprofile();
- girl.showprofile();
- }
- }
- class Family{
- String name,hobby;
- int age;
- Family(String n,int a,String h)
- {
- name=n;
- age=a;
- hobby=h;
- }
- void showprofile()
- {
- System.out.println(name+"今年"+age+",喜歡"+hobby+".");
- }
- }
複製代碼 |