標題:
物件導向基礎概念 (二)
[打印本頁]
作者:
tonyh
時間:
2021-12-11 19:26
標題:
物件導向基礎概念 (二)
定義一 Family 類別,並在Family類別下建立四個實體物件,分別為man、woman、boy 與 girl。同時,於Family類別下定義 showProfile() 方法用來顯示每位家庭成員的描述,並於 main 方法中呼叫它。
執行參考畫面如下:
本帖隱藏的內容需要回復才可以瀏覽
作者:
黃子倢
時間:
2021-12-11 19:54
public class Ch56 {
public static void main(String[] args) {
Family man=new Family("爸爸",40,"爬山");
Family woman=new Family("媽媽",38,"逛街");
Family boy=new Family("男孩",10,"打電動");
Family girl=new Family("女孩",8,"看書");
man.showProfile();
woman.showProfile();
boy.showProfile();
girl.showProfile();
}
}
class Family
{
String name;
int age;
String hobby;
Family(String n, int a, String h)
{
name=n;
age=a;
hobby=h;
}
void showProfile()
{
System.out.println(name+"今年"+age+"歲,喜歡"+hobby);
}
}
複製代碼
作者:
陳志祐
時間:
2021-12-11 19:54
本帖最後由 陳志祐 於 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+".");
}
}
複製代碼
作者:
余柏緯
時間:
2021-12-11 19:55
public class Ch510 {
public static void main(String[] args) {
Family man=new Family("爸爸", 40, "爬山");
Family woman=new Family("媽媽", 37, "逛街");
Family boy=new Family("男孩", 10, "打電動");
Family girl=new Family("女孩", 8, "看書");
man.showProfile();
woman.showProfile();
boy.showProfile();
girl.showProfile();
}
}
class Family
{
String name,hobby;
int age;
public Family(String n,int a, String h)
{
name=n;
age=a;
hobby=h;
}
void showProfile()
{
System.out.println(name+"今年"+age+"歲,喜歡"+hobby+".");
}
}
複製代碼
作者:
俞成章
時間:
2021-12-11 19:56
public class Ch56 {
public static void main(String[] args) {
Family man=new Family("爸爸",40,"爬山");
Family woman=new Family("媽媽",38,"逛街");
Family boy=new Family("男孩",10,"打電動");
Family girl=new Family("女孩",8,"看書");
man.showProfile();
woman.showProfile();
boy.showProfile();
girl.showProfile();
}
}
class Family
{
String name;
int age;
String hobby;
Family(String n, int a, String h)
{
name=n;
age=a;
hobby=h;
}
void showProfile()
{
System.out.println(name+"今年"+age+"歲,喜歡"+hobby);
}
}
複製代碼
作者:
許洧熏
時間:
2021-12-11 19:56
本帖最後由 許洧熏 於 2021-12-11 20:16 編輯
public class Ch01 {
public static void main(String[] args) {
Family man=new Family("爸爸",40,"爬山");
Family woman=new Family("媽媽",38,"逛街");
Family boy=new Family("男孩",10,"打電動");
Family girl=new Family("女孩",8,"看書");
man.showProfile();
woman.showProfile();
boy.showProfile();
girl.showProfile();
}
}
class Family
{
String name;
int age;
String hobby;
Family(String n, int a, String h)
{
name=n;
age=a;
hobby=h;
}
void showProfile()
{
System.out.println(name+"今年"+age+"歲,喜歡"+hobby);
}
}
複製代碼
作者:
林佑宸
時間:
2021-12-11 19:57
public class Ch02 {
public static void main(String[] args) {
Family man=new Family("爸爸", 40, "爬山");
Family woman=new Family("媽媽", 37, "逛街");
Family boy=new Family("男孩", 10, "打電動");
Family girl=new Family("女孩", 8, "看書");
man.showProfile();
woman.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+".");
}
}
複製代碼
作者:
王秉鈞
時間:
2021-12-11 19:58
本帖最後由 王秉鈞 於 2021-12-11 20:06 編輯
public class Ch25
public static void main(String[] args) {
{
Family man=new Family("爸爸",40,"爬山");
Family mom=new Family("媽媽",38,"逛街");
Family boy=new Family("哥哥",10,"打電動");
Family girl=new Family("妹妹",8,"看書");
man.showProfile();
mom.showProfile();
boy.showProfile();
girl.showProfile();
}
}
class Family
{
String name;
int age;
String hobby;
Family(String n,int a,String h)
{
name=n;
age=a;
hobby=h;
}
void showProfile()
{
System.out.println(name+"今年"+age+"歲 喜歡"+hobby);
}
}
}
}
複製代碼
作者:
林土水
時間:
2021-12-11 19:59
public class Ch01 {
public static void main(String[] args) {
Family man=new Family("爸爸",40,"爬山");
Family woman=new Family("媽媽",38,"逛街");
Family boy=new Family("男孩",10,"打電動");
Family girl=new Family("女孩",8,"看書");
man.showProfile();
woman.showProfile();
boy.showProfile();
girl.showProfile();
}
}
class Family
{
String name;
int age;
String hobby;
Family(String n, int a, String h)
{
name=n;
age=a;
hobby=h;
}
void showProfile()
{
System.out.println(name+"今年"+age+"歲,喜歡"+hobby);
}
}
複製代碼
作者:
蔡寓珉
時間:
2021-12-11 20:01
public class Ch58 {
public static void main(String[] args) {
Family man=new Family("爸爸",40,"爬山");
Family woman=new Family("媽媽",38,"逛街");
Family boy=new Family("男孩",10,"打電動");
Family girl=new Family("女孩",8,"看書");
man.showProfile();
woman.showProfile();
boy.showProfile();
girl.showProfile();
}
}
class Family
{
String name;
int age;
String hobby;
Family (String n, int a, String h)
{
name=n;
age=a;
hobby=h;
}
void showProfile()
{
System.out.println(name+"今年"+age+"歲,喜歡"+hobby);
}
}
複製代碼
作者:
林鼎傑
時間:
2021-12-11 20:02
public class Ch87 {
public static void main(String[] args)
{
Family man=new Family("爸爸",40,"爬山");
Family woman=new Family("媽媽",37,"逛街");
Family boy=new Family("弟弟",10,"打電動");
Family girl=new Family("妹妹",8,"看書");
man.showProFile();
woman.showProFile();
boy.showProFile();
girl.showProFile();
}
}
class Family
{
String name,d;
int age;
Family(String a ,int b, String c)
{
name=a;
age=b;
d=c;
}
void showProFile()
{
System.out.println(name+"今年"+age+"歲,喜歡"+d);
}
}
複製代碼
作者:
朱奕祐
時間:
2021-12-11 20:03
public class Ch01 {
public static void main(String[] args) {
Fmaily man=new Fmaily("爸爸"40,"爬山");
Fmaily man=new Fmaily("媽媽"37,"逛街");
Fmaily man=new Fmaily("弟弟"10,"打電動");
Fmaily man=new Fmaily("妹妹"40,"讀書");
man.showProfile();
woman.showProfile();
boy.showProfile();
girl.showProfile();
}
}
class Family
{
String name,hobby;
int age;
Fmaily(String n, int a, String h)
{
name=n;
age=a;
hobby=h;
}
void showProfile()
{
System.out.println(name+"今年"+age+"歲,喜歡"+hobby);
複製代碼
作者:
呂尚霖
時間:
2021-12-11 20:35
public class Ch02 {
public static void main(String[] args) {
Family man=new Family("爸爸",40,"爬山");
Family woman=new Family("媽媽",38,"逛街");
Family boy=new Family("男孩",10,"打電動");
Family girl=new Family("女孩",8,"看書");
man.showProfile();
woman.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);
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2