# 實例變數 與 實例函數

> 實例變數：獨立，存在於不同記憶體
>
> 實例函數：必須透過物件來呼叫

將會帶入 [公有與私有 ( public & private) – 類別成員篇](/java-08/java-08-8.md) 其中的內容

```
class CCircle
{
   private double pi=3.14;
   private double radius;

   public CCircle(double r)   //建構元
   {
      radius=r;
   }
   public void show()
   {
      System.out.println("area="+pi*radius*radius);
   }
}
public class instance_vs_class_01
{
   public static void main(String args[])
   {
      CCircle cir1=new CCircle(1.0);
      cir1.show();         //透過物件來呼叫show
      CCircle cir2=new CCircle(2.0);
      cir2.show();         //透過物件來呼叫show
   }
}
```

在主程式部分： 可參考 [**認識 建構元**](/java-09/java-09-1.md)

建立物件 cir1 與 cir2 因此他們擁有自己存資料的記憶體空間，\
就像 cir1 有自己的一間房間，而 cir2 也有屬於自己的房間；\
兩者的房間不共用。

```
CCircle cir1=new CCircle(1.0);
cir1.show();         //透過物件來呼叫show
CCircle cir2=new CCircle(2.0);
cir2.show();         //透過物件來呼叫show
```

截至目前（若按照本站文章進度的話，認識了類別三樣元件：資料成員、函數成員、建構元）；\
而在先前的範例都是使用到實例變數與實例函數。

讓我們再次複習一次 實例變數 與 實例函數 是什麼：

> 實例變數：獨立，存在於不同記憶體
>
> 實例函數：必須透過物件來呼叫

接下來我們要帶入 類別變數 與 類別函數 來與剛剛複習的 實例變數 與 實例函數 做比較


---

# 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-10/java-10-1.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.
