//車子類別
class Car
{
int num;
double gas;
void show() //這是方法
{
System.out.println("車號是" + num + "。");
System.out.println("汽油量是" + gas + "。");
}
void showCar()
{
System.out.println("開始顯示車子的資料。");
show(); //這表示呼叫「物件本身」的方法的意思
}
}
class Sample3
{
public static void main(String[] args)
{
Car car1;
car1=new Car();
car1.num=1234;
car1.gas=20.5;
car1.showCar(); //這表示呼叫car1的方法的意思
}
}
沒有留言:
張貼留言