# 類別中的函數成員相互呼叫

以[上一篇](/java-08/java-08-2.md)中的範例做示範與修改

```
class CRectangle {  //定義矩形類別
	//資料成員
	int width;  //寬
	int height; //長
	//函數成員
	int area(){   //計算面積
		System.out.println("面積＝ "+width*height);
		}
	int perimeter(){  //計算周長
		System.out.println("周長＝ "+2*(width+height);
		}
        int show_all(){  //在show_all 函數中 呼叫計算面積的函數與計算周長的函數
                System.out.println("寬＝ "+width+" ,長＝ "+height);
                area();  //呼叫計算面積的函數
                perimeter(); //呼叫計算周長的函數
                }

}
public class ch08_3 {

	public static void main(String[] args) {
		CRectangle book;   //宣告CRectangle類別的變數 book
		book= new CRectangle(); //建立物件

		book.width=10;  //給寬一個值
		book.height=5;  //給長一個值
		book.show_all(); //呼叫show_all()
	}
}
```

輸出結果：\
寬＝ 10 ,長＝ 5\
面積＝ 50\
面積＝ 30

在類別中函數成員的程式碼敘述當中，直接加上類別中其他函數成員的函數名稱即可呼叫。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://java.4-x.tw/java-08/java-08-3.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
