主程式- package Test9;
- public class Ch99 {
- public class Ch03 {
- public static void main(String[] args) {
- // TODO 自動產生的方法 Stub
- Family dad=new Family("爸爸",40,"爬山");
- dad.showProfile();
- Family mom=new Family("媽媽",37,"逛街");
- mom.showProfile();
- Family boy=new Family("男孩",10,"打電動");
- boy.showProfile();
- Family girl=new Family("女孩",8,"看書");
- girl.showProfile();
- }
- }
- class family
- {
- String n;
- int y;
- String h;
- family(String name,int years,String hobby)
- {
- n=name;
- y=years;
- h=hobby;
- }
- void showProfile()
- {
- System.out.println(n+"今年幾"+y+"歲,喜歡"+h+".");
- }
- }
- }
複製代碼 fAMILY- package Test9;
- public class Family {
- int age;
- String Name,hobby;
-
- Family(String n,int a,String h)
- {
-
- age = a;
- Name = n;
- hobby = h;
- }
- void show()
- {
- System.out.println(Name + "今年" + age + "歲,喜歡" + hobby);
- }
- public void showProfile() {
- // TODO Auto-generated method stub
-
- }
- }
複製代碼 |