this . 資料成員名稱 ;
this . 函數成員名稱 ;
class CRectangle { //定義矩形類別
//資料成員
int width; //寬
int height; //長
//函數成員
int area(){ //計算面積
System.out.println("面積= "+this.width*this.height);
}
int perimeter(){ //計算周長
System.out.println("周長= "+2*(this.width+this.height);
}
int show_all(){ //在show_all 函數中 呼叫計算面積的函數與計算周長的函數
System.out.println("寬= "+this.width+" ,長= "+this.height);
this.area(); //呼叫計算面積的函數
this.perimeter(); //呼叫計算周長的函數
}
}
public class ch08_4 {
public static void main(String[] args) {
CRectangle book; //宣告CRectangle類別的變數 book
book= new CRectangle(); //建立物件
book.width=10; //給寬一個值
book.height=5; //給長一個值
book.show_all(); //呼叫show_all()
}
}
name(String book){
book=book;
}
name(String book){
this.book=book;
}