標題:
物件導向基礎概念 (二)
[打印本頁]
作者:
葉桔良
時間:
2023-4-22 15:24
標題:
物件導向基礎概念 (二)
定義一 Family 類別,並在Family類別下建立四個實體物件,分別為man、woman、boy 與 girl。同時,於Family類別下定義 showProfile() 方法用來顯示每位家庭成員的描述,並於 main 方法中呼叫它。
執行參考畫面如下:
本帖隱藏的內容需要積分高於 1 才可瀏覽
作者:
錢冠叡
時間:
2023-4-22 17:22
主程式
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
}
}
複製代碼
作者:
柏霖
時間:
2023-4-22 17:22
main
public class Ch05 {
public static void main(String[] args) {
family man=new family("爸爸", 40 , "爬山");
man.show();
family woman=new family("媽媽", 37 , "逛街");
woman.show();
family boy=new family("男孩", 10 , "打電動");
boy.show();
family girl=new family("女孩", 8 , "看書");
girl.show();
}
}
複製代碼
family
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);
}
}
複製代碼
作者:
許浩浩
時間:
2023-4-22 17:30
public class Ch02 {
public static void main(String[] args) {
// TODO 自動產生的方法 Stub
Family man=new Family("爸爸",40,"爬山");
man.show();
Family woman=new Family("媽媽",37,"逛街");
woman.show();
Family boy=new Family("男孩",10,"打電動");
boy.show();
Family mann=new Family("女孩",8,"看書");
mann.show();
}
}
複製代碼
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);
}
}
複製代碼
作者:
張駿霖
時間:
2023-4-22 17:30
主程式:
public class Ch01 {
public static void main(String[] args) {
// TODO 自動產生的方法 Stub
Family man = new Family("爸爸",40,"爬山");
man.show();
Family woman = new Family("媽媽",37,"逛街");
woman.show();
Family boy = new Family("男孩",40,"爬山");
boy.show();
Family girl = new Family("女孩",37,"逛街");
girl.show();
}
}
Family:
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);
}
}
複製代碼
作者:
孫文康
時間:
2023-4-22 17:30
Ch01
public class Ch01 {
public static void main(String[] args) {
Family man=new Family("爸爸",40,"爬山");
man.show();
Family woman =new Family("媽媽",37,"逛街");
woman.show();
Family boy =new Family("男孩",10,"打電動");
boy.show();
Family girl =new Family("女孩",8,"看書");
girl.show();
}
}
複製代碼
Family
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);
}
}
複製代碼
作者:
謝閔丞
時間:
2023-4-22 17:32
主程式
package b;
public class Ch01 {
public static void main(String[] args) {
// TODO 自動產生的方法 Stub
family man = new family("爸爸",40,"爬山");
man.show();
family woman = new family("媽媽",37,"逛街");
woman.show();
family boy = new family("男孩",10,"打電動");
boy.show();
family girl = new family("女孩",8,"看書");
girl.show();
}
}
複製代碼
family
package b;
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);
}
}
複製代碼
作者:
石皓云
時間:
2023-4-22 17:37
主程式
public class Ch01 {
public static void main(String[] args) {
// TODO 自動產生的方法 Stub
f man=new f("爸爸",40,"玩手機");
man.show();
f mom=new f("媽媽",37,"看書");
mom.show();
f my=new f("我",11,"打電動");
my.show();
f girl=new f("妹妹",7,"看電視");
girl.show();
}
}
複製代碼
f
public class f {
int age;
String Name,hobby;
f(String n,int a,String h){
age=a;
Name=n;
hobby=h;
}
void show(){
System.out.println(Name+"今年"+age+"歲,喜歡"+hobby);
}
}
複製代碼
作者:
侯宣任
時間:
2023-4-24 21:13
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
}
}
複製代碼
作者:
侯宣仲
時間:
2023-4-24 21:31
public class Ch01 {
public static void main(String[] args) {
// TODO 自動產生的方法 Stub
f man=new f("爸爸",40,"玩手機");
man.show();
f mom=new f("媽媽",37,"看書");
mom.show();
f my=new f("我",11,"打電動");
my.show();
f girl=new f("妹妹",7,"看電視");
girl.show();
}
}
複製代碼
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);
}
}
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2