標題:
物件導向基礎概念 (一)
[打印本頁]
作者:
周政輝
時間:
2018-10-13 14:35
標題:
物件導向基礎概念 (一)
定義一 Car 類別, 並在Car類別下建立三個實體物件, 分別為bus, truck 與 taxi.
執行參考畫面如下:
[attach]5025[/attach]
作者:
王駿愷
時間:
2018-10-13 15:06
package mhjhmtc;
public class D {
public static void main(String[] args) {
// TODO 自動產生的方法 Stub
Car truck = new Car();
truck.carName="卡車";
truck.wheels=6;
truck.people=3;
System.out.printf("%s有%d個輪子載%d個人\n\r",truck.carName,truck.wheels,truck.people);
Car bus=new Car();
bus.carName="公車";
bus.wheels=8;
bus.people=40;
System.out.printf("%s有%d個輪子載%d個人\n\r",bus.carName,bus.wheels,bus.people);
Car taxi=new Car();
taxi.carName="計程車";
taxi.wheels=4;
taxi.people=4;
System.out.printf("%s有%d個輪子載%d個人\n\r",taxi.carName,taxi.wheels,taxi.people);
}
}
複製代碼
作者:
高允懋
時間:
2018-10-13 15:06
package kao;
public class Main
{
public static void main(String[] args)
{
Car bus = new Car();
bus.carname="公車";
bus.wheels=6;
bus.people=40;
System.out.printf("%s有%d個輪子,可載%d個人\r\n",bus.carname,bus.wheels,bus.people);
Car truck = new Car();
truck.carname="卡車";
truck.wheels=8;
truck.people=3;
System.out.printf("%s有%d個輪子,可載%d個人\r\n",truck.carname,truck.wheels,truck.people);
Car taxi = new Car();
taxi.carname="計程車";
taxi.wheels=4;
taxi.people=5;
System.out.printf("%s有%d個輪子,可載%d個人\r\n",taxi.carname,taxi.wheels,taxi.people);
}
}
複製代碼
作者:
湯東緯
時間:
2018-10-13 15:12
package main;
public class D {
public static void main(String[] args) {
// TODO 自動產生的方法 Stub
Car truck = new Car();
truck.carName="卡車";
truck.wheels=6;
truck.people=3;
System.out.printf("%s有%d個輪子載%d個人\n\r",truck.carName,truck.wheels,truck.people);
Car bus=new Car();
bus.carName="公車";
bus.wheels=8;
bus.people=40;
System.out.printf("%s有%d個輪子載%d個人\n\r",bus.carName,bus.wheels,bus.people);
Car taxi=new Car();
taxi.carName="計程車";
taxi.wheels=4;
taxi.people=4;
System.out.printf("%s有%d個輪子載%d個人\n\r",taxi.carName,taxi.wheels,taxi.people);
}
}
複製代碼
作者:
黃安立
時間:
2018-10-13 15:13
package 顏詢大笨蛋1;
import java.util.Scanner;
public class 顏詢大笨蛋2 {
// 一個專案只會有一個(程式進入點)
public static void main(String[] args){
int a =10;
Car truck =new Car();
truck.carName="";
truck.wheels=8;
truck.people=3;
system.out.printf ("%s有%b",truck.carname,truck.wheel,truck.people);
Car bus =new Car();
truck.carName=" 巴士";
truck.wheels=6;
truck.people=40;
system.out.printf ("%s有%b",taxi.carname,taxi.wheel,taxi.people);
Car taxi =new Car();
truck.carName="計程車 ";
truck.wheels=4;
truck.people=5;
}
}
複製代碼
作者:
吳秉翰
時間:
2018-10-13 15:16
package bn.tw;
public class Main {
public static void main(String[] args) {
// TODO 自動產生的方法 Stub
Car bus = new Car();
bus.carName = "公車";
bus.wheels = 6;
bus.passengerAmount = 40;
System.out.printf("%s有%d個輪子載%d個人\n\r", bus.carName, bus.wheels,
bus.passengerAmount);
Car truck = new Car();
truck.carName = "卡車";
truck.wheels = 8;
truck.passengerAmount = 3;
System.out.printf("%s有%d個輪子載%d個人\n\r", truck.carName, truck.wheels,
truck.passengerAmount);
Car taxi = new Car();
taxi.carName = "計程車";
taxi.wheels = 4;
taxi.passengerAmount = 4;
System.out.printf("%s有%d個輪子載%d個人\n\r", taxi.carName, taxi.wheels,
taxi.passengerAmount);
}
}
複製代碼
作者:
彭煥宇
時間:
2018-10-20 13:17
package bbs.istak.org.tw;
public class Main {
public static void main(String[] args) {
Car bus = new Car();
bus.carname="公車";
bus.wheels=6;
bus.people=40;
System.out.printf("%s有%d個輪子,可載%d個人\r\n",bus.carname,bus.wheels,bus.people);
Car truck = new Car();
truck.carname="卡車";
truck.wheels=8;
truck.people=3;
System.out.printf("%s有%d個輪子,可載%d個人\r\n",truck.carname,truck.wheels,truck.people);
Car taxi = new Car();
taxi.carname="計程車";
taxi.wheels=4;
taxi.people=5;
System.out.printf("%s有%d個輪子,可載%d個人\r\n",taxi.carname,taxi.wheels,taxi.people);
}
}
複製代碼
作者:
鄭楀諺
時間:
2018-10-20 13:22
public class momo {
public static void main(String[] args) {
// TODO 自動產生的方法 Stub
Car bus=new Car();
bus.name="Bus";
bus.wheel=8;
bus.load=40;
bus.output();
Car truck=new Car();
bus.name="Truck";
bus.wheel=6;
bus.load=3;
bus.output();
Car taxi=new Car();
bus.name="Taxi";
bus.wheel=4;
bus.load=4;
bus.output();
}
}
class Car
{
String name;
int wheel;
int load;
void output()
{
System.out.println(this.name+" have "+this.wheel+" wheels,it can load "+this.load+" people.");
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2