標題:
物件導向基礎概念 (一)
[打印本頁]
作者:
tonyh
時間:
2013-8-17 16:30
標題:
物件導向基礎概念 (一)
public class ch71 //主類別
{
public static void main(String args[]) //主方法(主函式)
{
Car bus=new Car(); //於Car類別下,宣告物件並產生實體,分別命名為bus,truck,taxi
Car truck=new Car();
Car taxi=new Car();
bus.name="公車"; //定義 bus 這個物件的屬性
bus.wheel=6;
bus.person=40;
truck.name="卡車";
truck.wheel=8;
truck.person=3;
taxi.name="計程車";
taxi.wheel=4;
taxi.person=5;
System.out.println(bus.name+"有"+bus.wheel+"個輪子,可載"+bus.person+"人");
System.out.println(truck.name+"有"+truck.wheel+"個輪子,可載"+truck.person+"人");
System.out.println(taxi.name+"有"+taxi.wheel+"個輪子,可載"+taxi.person+"人");
}
}
class Car //定義 Car 類別, 並宣告該類別中的三個變數(屬性)
{
int wheel;
int person;
String name;
}
複製代碼
作者:
t2364705
時間:
2013-8-17 16:32
public class ch71
{
public static void main(String args[])
{
Car bus=new Car();
Car truck=new Car();
Car taxi=new Car();
bus.name="公車";
bus.wheel=6;
bus.person=40;
truck.name="卡車";
truck.wheel=8;
truck.person=3;
taxi.name="計程車";
taxi.wheel=4;
taxi.person=5;
System.out.println(bus.name+"有"+bus.wheel+"個輪子,可載"+bus.person+"人");
System.out.println(truck.name+"有"+truck.wheel+"個輪子,可載"+truck.person+"人");
System.out.println(taxi.name+"有"+taxi.wheel+"個輪子,可載"+taxi.person+"人");
}
}
class Car
{
int wheel;
int person;
String name;
}
複製代碼
作者:
t3742238
時間:
2013-8-17 16:35
public class ch71
{
public static void main(String args[])
{
Car bus=new Car();
Car truck=new Car();
Car taxi=new Car();
bus.name="公車";
bus.wheel=6;
bus.person=40;
truck.name="卡車";
truck.wheel=8;
truck.person=3;
taxi.name="計程車";
taxi.wheel=4;
taxi.person=5;
System.out.println(bus.name+"有"+bus.wheel+"個輪子,可載"+bus.person+"人");
System.out.println(truck.name+"有"+truck.wheel+"個輪子,可載"+truck.person+"人");
System.out.println(taxi.name+"有"+taxi.wheel+"個輪子,可載"+taxi.person+"人");
}class Car
{
int wheel;
int person;
String name;
}
}
複製代碼
作者:
黃博鴻
時間:
2013-8-17 16:36
public class ch71
{
public static void main(String args[])
{
Car bus=new Car();
Car truck=new Car();
Car taxi=new Car();
bus.name="公車";
bus.wheel=6;
bus.preson=40;
truck.name="卡車";
truck.wheel=8;
truck.preson=3;
taxi.name="計程車";
taxi.wheel=4;
taxi.preson=5;
System.out.println(bus.name+"有"+bus.wheel+"個輪子,可載"+bus.preson+"人");
System.out.println(truck.name+"有"+truck.wheel+"個輪子,可載"+truck.preson+"人");
System.out.println(taxi.name+"有"+taxi.wheel+"個輪子,可載"+taxi.preson+"人");
}
}
class Car
{
int wheel;
int preson;
String name;
}
複製代碼
作者:
劉漢文
時間:
2013-8-17 17:13
public class ch71
{
public static void main(String args[])
{
Car bus=new Car();
Car truck=new Car();
Car taxi=new Car();
bus.name="公車";
bus.wheel=6;
bus.person=40;
truck.name="卡車";
truck.wheel=8;
truck.person=3;
taxi.name="計程車";
taxi.wheel=4;
taxi.person=5;
System.out.println(bus.name+"有"+bus.wheel+"個輪子,可載"+bus.person+"人");
System.out.println(truck.name+"有"+truck.wheel+"個輪子,可載"+truck.person+"人");
System.out.println(taxi.name+"有"+taxi.wheel+"個輪子,可載"+taxi.person+"人");
}class Car
{
int wheel;
int person;
String name;
}
}
複製代碼
作者:
尤泓鈞
時間:
2013-8-21 20:37
public class ch71
{
public static void main(String args[])
{
Car bus=new Car();
Car truck=new Car();
Car taxi=new Car();
bus.name="公車";
bus.wheel=6;
bus.person=40;
truck.name="卡車";
truck.wheel=8;
truck.person=3;
taxi.name="計程車";
taxi.wheel=4;
taxi.person=5;
System.out.println(bus.name+"有"+bus.wheel+"個輪子,可載"+bus.person);
System.out.println(truck.name+"有"+truck.wheel+"個輪子,可載"+truck.person);
System.out.println(taxi.name+"有"+taxi.wheel+"個輪子,可載"+taxi.person);
}
}
class Car
{
int wheel;
int person;
String name;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2