- 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;
- }
複製代碼 |