Related Posts Plugin for WordPress, Blogger... 簡單易懂的低調手札: [MEMO] JAVA 實作 this

2011年10月24日 星期一

[MEMO] JAVA 實作 this

package test;

public class test111024 {

public static void main (String args[])
{

Car car = new Car(4,"Benz");
car.printData();

}


}

class Car{

protected int wheel;
protected String name;

public Car(int wheel,String name)
{

this.name = name;
this.wheel = wheel;


}



public void printData()
{

System.out.println("The car has: " + wheel + " wheels.");
System.out.println();
System.out.println("The car's name is: " + name + ".");
}
}

沒有留言:

張貼留言