標題:
[作業] 物件導向基礎概念 (二)
[打印本頁]
作者:
周政輝
時間:
2018-10-13 15:18
標題:
[作業] 物件導向基礎概念 (二)
定義一 Family 類別, 並在Family類別下建立四個實體物件, 分別為man, woman, boy 與 girl.
執行參考畫面如下:
[attach]5028[/attach]
作者:
王駿愷
時間:
2018-10-13 15:28
package mhjhmtc;
public class D {
public static void main(String[] args) {
// TODO 自動產生的方法 Stub
family dad=new family();
dad.familyname="爸爸";
dad.edge=40;
dad.activity="爬山";
System.out.printf("%s%d歲喜歡%s\n\r",dad.familyname,dad.edge,dad.activity);
family mom=new family();
mom.familyname="媽媽";
mom.edge=39;
mom.activity="逛街";
System.out.printf("%s%d歲喜歡%s\n\r",mom.familyname,mom.edge,mom.activity);
family sister=new family();
sister.familyname="姐姐";
sister.edge=18;
sister.activity="看影片";
System.out.printf("%s%d歲喜歡%s\n\r",sister.familyname,sister.edge,sister.activity);
family brother=new family();
brother.familyname="弟弟";
brother.edge=10;
brother.activity="打電動";
System.out.printf("%s%d歲喜歡%s\n\r",brother.familyname,brother.edge,brother.activity);
}
}
複製代碼
作者:
高允懋
時間:
2018-10-13 15:31
package kao;
public class Main
{
public static void main(String[] args)
{
Family dad = new Family();
dad.people="爸爸";
dad.age=40;
dad.hobby="爬山";
System.out.printf("%s今年%d歲,喜歡%s\r\n",dad.people,dad.age,dad.hobby);
Family mom = new Family();
mom.people="媽媽";
mom.age=37;
mom.hobby="逛街";
System.out.printf("%s今年%d歲,喜歡%s\r\n",mom.people,mom.age,mom.hobby);
Family boy = new Family();
boy.people="男孩";
boy.age=10;
boy.hobby="打電動";
System.out.printf("%s今年%d歲,喜歡%s\r\n",boy.people,boy.age,boy.hobby);
Family girl = new Family();
girl.people="女孩";
girl.age=8;
girl.hobby="看書";
System.out.printf("%s今年%d歲,喜歡%s\r\n",girl.people,girl.age,girl.hobby);
}
}
複製代碼
作者:
吳秉翰
時間:
2018-10-13 15:32
本帖最後由 吳秉翰 於 2018-10-16 20:44 編輯
package bn.tw;
public class Main {
public static void main(String[] args) {
// TODO 自動產生的方法 Stub
Family man=new Family();
man.age=40;
man.hob="爬山";
System.out.printf("爸爸%d歲喜歡%s\n\r",man.age,man.hob);
Family woman=new Family();
woman.age=37;
woman.hob="逛街";
System.out.printf("媽媽%d歲喜歡%s\n\r",woman.age,woman.hob);
Family boy=new Family();
boy.age=10;
boy.hob="打電動";
System.out.printf("男孩%d歲喜歡%s\n\r",boy.age,boy.hob);
Family girl=new Family();
girl.age=8;
girl.hob="看書";
System.out.printf("女孩%d歲喜歡%s\n\r",girl.age,girl.hob);
}
}
複製代碼
作者:
黃安立
時間:
2018-10-20 11:33
本帖最後由 黃安立 於 2018-10-20 11:35 編輯
package CH01;
public class eric_
{
public static void main(String[] args)
{
Family dad = new Family();
dad.people="爸爸";
dad.age=40;
dad.hobby="爬山";
System("%s今年%d歲,喜歡%s\r\n",dad.people,dad.age,dad.hobby);
Family mom = new Family();
mom.people="媽媽";
mom.age=37;
mom.hobby="買包包";
System("%s今年%d歲,喜歡%s\r\n",mom.people,mom.age,mom.hobby);
Family boy = new Family();
boy.people="男孩";
boy.age=10;
boy.hobby="睡覺";
System("%s今年%d歲,喜歡%s\r\n",boy.people,boy.age,boy.hobby);
Family girl = new Family();
girl.people="女孩";
girl.age=8;
girl.hobby="吃泡麵";
System("%s今年%d歲,喜歡%s\r\n",girl.people,girl.age,girl.hobby);
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2