標題:
物件導向基礎概念 (二)
[打印本頁]
作者:
tonyh
時間:
2013-8-17 17:07
標題:
物件導向基礎概念 (二)
public class ch72 //主類別
{
public static void main(String args[]) //主方法(主函式)
{
Family man=new Family(); //於Family類別下,新增man這個物件
Family woman=new Family();
Family boy=new Family();
Family girl=new Family();
man.name="爸爸";
man.age=40;
man.hobby="爬山";
man.income=50000;
woman.name="媽媽";
woman.age=37;
woman.hobby="逛街";
boy.name="男孩";
boy.age=10;
boy.hobby="打電動";
girl.name="女孩";
girl.age=8;
girl.hobby="看書";
System.out.println(man.name+"今年"+man.age+"歲,喜歡"+man.hobby+",月收入"+man.income+"元");
System.out.println(woman.name+"今年"+woman.age+"歲,喜歡"+woman.hobby);
System.out.println(boy.name+"今年"+boy.age+"歲,喜歡"+boy.hobby);
System.out.println(girl.name+"今年"+girl.age+"歲,喜歡"+girl.hobby);
}
}
class Family //定義 Family 類別, 並宣告該類別中的變數(屬性)
{
int age;
String name;
String hobby;
int income;
}
複製代碼
作者:
t2364705
時間:
2013-8-17 17:13
public class ch72
{
public static void main(String args[])
{
Family man=new Family();
Family woman=new Family();
Family boy=new Family();
Family girl=new Family();
man.name="爸爸";
man.age=40;
man.hobby="爬山";
man.income=50000;
woman.name="媽媽";
woman.age=37;
woman.hobby="逛街";
boy.name="男孩";
boy.age=10;
boy.hobby="打電動";
girl.name="女孩";
girl.age=8;
girl.hobby="看書";
System.out.println(man.name+"今年"+man.age+"歲,喜歡"+man.hobby+",月收入"+man.income+"元");
System.out.println(woman.name+"今年"+woman.age+"歲,喜歡"+woman.hobby);
System.out.println(boy.name+"今年"+boy.age+"歲,喜歡"+boy.hobby);
System.out.println(girl.name+"今年"+girl.age+"歲,喜歡"+girl.hobby);
}
}
class Family
{
int age;
String name;
String hobby;
int income;
}
複製代碼
作者:
黃博鴻
時間:
2013-8-17 17:14
public class ch72
{
public static void main(String args[])
{
Family man=new Family();
Family woman=new Family();
Family boy=new Family();
Family girl=new Family();
man.name="爸爸";
man.age=40;
man.hobby="爬山";
woman.name="媽媽";
woman.age=37;
woman.hobby="逛街";
boy.name="男孩";
boy.age=10;
boy.hobby="打電動";
girl.name="女孩";
girl.age=8;
girl.hobby="看書";
System.out.println(man.name+"今年"+man.age+"歲,喜歡"+man.hobby);
System.out.println(woman.name+"今年"+woman.age+"歲,喜歡"+woman.hobby);
System.out.println(boy.name+"今年"+boy.age+"歲,喜歡"+boy.hobby);
System.out.println(girl.name+"今年"+girl.age+"歲,喜歡"+girl.hobby);
}
}
class Family
{
int age;
String hobby;
String name;
}
複製代碼
作者:
t3742238
時間:
2013-8-17 17:16
public class ch72
{
public static void main(String args[])
{
Family man=new Family();
Family woman=new Family();
Family boy=new Family();
Family girl=new Family();
man.name="爸爸";
man.age=40;
man.hobby="爬山";
man.income=50000;
woman.name="媽媽";
woman.age=37;
woman.hobby="逛街";
boy.name="男孩";
boy.age=10;
boy.hobby="打電動";
girl.name="女孩";
girl.age=8;
girl.hobby="看書";
System.out.println(man.name+"今年"+man.age+"歲,喜歡"+man.hobby+",月收入"+man.income+"元");
System.out.println(woman.name+"今年"+woman.age+"歲,喜歡"+woman.hobby);
System.out.println(boy.name+"今年"+boy.age+"歲,喜歡"+boy.hobby);
System.out.println(girl.name+"今年"+girl.age+"歲,喜歡"+girl.hobby);
}
}
class Family
{
int age;
String name;
String hobby;
int income;
}
複製代碼
作者:
劉漢文
時間:
2013-8-17 17:19
public class ch72
{
public static void main(String args[])
{
Family man=new Family();
Family woman=new Family();
Family boy=new Family();
Family girl=new Family();
man.name="爸爸";
man.age=40;
man.hobby="爬山";
woman.name="媽媽";
woman.age=37;
woman.hobby="逛街";
boy.name="男孩";
boy.age=10;
boy.hobby="打電動";
girl.name="女孩";
girl.age=8;
girl.hobby="看書";
System.out.println(man.name+"今年"+man.age+"歲,喜歡"+man.hobby);
System.out.println(woman.name+"今年"+woman.age+"歲,喜歡"+woman.hobby);
System.out.println(boy.name+"今年"+boy.age+"歲,喜歡"+boy.hobby);
System.out.println(girl.name+"今年"+girl.age+"歲,喜歡"+girl.hobby);
}
}
class Family
{
int age;
String hobby;
String name;
}
複製代碼
作者:
尤泓鈞
時間:
2013-8-21 20:38
public class ch72
{
public static void main(String args[])
{
Family man=new Family();
Family woman=new Family();
Family girl=new Family();
Family boy=new Family();
man.name="爸爸";
man.age=40;
man.hobby="爬山";
man.income=50000;
woman.name="媽媽";
woman.age=37;
woman.hobby="逛街";
woman.income=50000;
girl.name="女孩";
girl.age=8;
girl.hobby="看書";
man.name="男孩";
man.age=10;
man.hobby="打電動";
System.out.println(man.name+"今年"+man.age+"歲,興趣"+man.hobby+"月收入"+man.income+"元");
System.out.println(woman.name+"今年"+woman.age+"歲,興趣"+woman.hobby+"月收入"+woman.income+"元");
System.out.println(girl.name+"今年"+girl.age+"歲,興趣"+girl.hobby);
System.out.println(boy.name+"今年"+boy.age+"歲,興趣"+boy.hobby);
}
}
class Family
{
int age;
String name;
String hobby;
int income;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2