# 傳遞引數與回傳值

於[上一篇 練習](/java-08/java-08-p.md) 帶入本次的傳遞引數以及回傳值

在以下範例，將示範關於引數傳遞。

```
class Circle{
	double pi=3.14;
	double radius;

	void show(){
		System.out.println("半徑＝ "+radius);
                System.out.println("面積＝ "+pi*radius*radius);
	}
        void set_r(double r){   //set_r 函數，用來設定半徑
	        radius=r;    //此處的r為區域變數，因此只會在此set_r函數中使用，離開將無效
	}
}
public class ch08_3 {

	public static void main(String[] args) {
		Circle moon=new Circle();
		moon.set_r(2);
		moon.show();
	}

}
```

看到類別中 函數成員set\_r

```
void set_r(double r){   //宣告一個變數r為double型態 作為引數
	radius=r;    //再設定radius 的值為引數r
}
```

於主程式中，呼叫類別函數

```
moon.set_r(2);   //設定moon 的半徑為 2
```

主程式中，設定半徑為2 會將此數值，\
傳到類別中的函數成員 set\_r() 的引數 r。

而在函數成員 set\_r 中，\
程式敘述又設定 radius 的值 為引數 r = 2

當主程式呼叫類別函數成員 show() 時，\
就會印出剛剛在函數成員 set\_r 設定給 radius 的值；\
以及利用設定後的radius算出 面積 並且印出。


---

# 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-5.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.
