- public class Ch58
- {
- public static void main(String args[])
- {
- Car bus=new Car();
- bus.name="公車";
- bus.wheel=6;
- bus.load=40;
- Car truck=new Car();
- truck.name="卡車";
- truck.wheel=8;
- truck.load=3;
-
- Car taxi=new Car();
- taxi.name="計程車";
- taxi.wheel=4;
- taxi.load=5;
-
- System.out.println(bus.name+"有"+bus.wheel+""+bus.load+"人");
- System.out.println(truck.name+""+truck.wheel+""+truck.load+"");
- System.out.println(taxi.name+""+taxi.wheel+""+taxi.load+"");
- }
- }
- class Car
- {
- String name;
- int wheel;
- int load;
- //建構子 (尚未定義)
- //方法 (尚未定義)
- }
複製代碼 |