標題:
物件導向基礎概念 (二)
[打印本頁]
作者:
tonyh
時間:
2013-5-29 20:32
標題:
物件導向基礎概念 (二)
public class ch32 //類別
{
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=38;
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 name;
String hobby;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2