<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # Java 中的實例變量 > 原文: [https://javabeginnerstutorial.com/core-java-tutorial/instance-variable-java/](https://javabeginnerstutorial.com/core-java-tutorial/instance-variable-java/) 對象使用 Java 中的實例變量存儲其狀態。 沒有使用`STATIC`關鍵字定義的變量,并且在任何方法聲明之外的都是特定于對象的,稱為實例變量。 之所以這樣稱呼它們,是因為它們的值特定于實例,**而不是**在實例之間共享。 ## 實例變量示例 ```java class Page { public String pageName; // instance variable with public access private int pageNumber; // instance variable with private access } ``` ## Java 中實例變量的規則 * 實例變量可以使用四個[訪問級別](https://javabeginnerstutorial.com/core-java-tutorial/access-modifier-in-java/)中的任何一個 * 他們可以標記為最終 * 可以將它們標記為瞬態 * 它們不能標記為抽象 * 無法將它們標記為已同步 * 它們不能標記為`strictfp` * 它們不能被標記為本地 * 它們不能標記為靜態 ## 備忘單 * `public, private, protected`所有這三種訪問修飾符都可以應用于實例變量(**默認**)。 * *實例變量*可以標記為`final`。 * *實例變量*可以標記為`transient`。 * *實例變量*不能是`abstract`。 * *實例變量*無法具有`syncronized`修飾符。 * *實例變量*無法具有`strictfp`修飾符。 * *實例變量*無法具有`native`修飾符。 * *實例變量*不能具有`static`修飾符,因為它會變為類級別的變量。 * 實例變量將獲得默認值,這意味著無需初始化即可使用實例變量。 對于*局部變量*,情況并非如此。 | 實例變量類型 | 默認值 | | --- | --- | | `boolean` | `false` | | `byte` | `(char)0` | | `short` | `(short)0` | | `int` | `0` | | `long` | `0l` | | `char` | `\u0000` | | `float` | `0.0f` | | `double` | `0.0d` | | `Object` | `null` | ```java package com.jbt; /* * Here we will discuss about different type of Variables available in Java */ public class VariablesInJava { /* * Below variable is INSTANCE VARIABLE as it is outside any method and it is * not using STATIC modifier with it. It is using default access modifier. * To know more about ACCESS MODIFIER visit appropriate section */ int instanceField; /* * Below variable is STATIC variable as it is outside any method and it is * using STATIC modifier with it. It is using default access modifier. To * know more about ACCESS MODIFIER visit appropriate section */ static String staticField; public void method() { /* * Below variable is LOCAL VARIABLE as it is defined inside method in * class. Only modifier that can be applied on local variable is FINAL. * To know more about access and non access modifier visit appropriate * section. * * Note* : Local variable needs to initialize before they can be used. * Which is not true for Static or Instance variable. */ final String localVariable = "Initial Value"; System.out.println(localVariable); } public static void main(String args[]) { VariablesInJava obj = new VariablesInJava(); /* * Instance variable can only be accessed by Object of the class only as below. */ System.out.println(obj.instanceField); /* * Static field can be accessed in two way. * 1- Via Object of the class * 2- Via CLASS name */ System.out.println(obj.staticField); System.out.println(VariablesInJava.staticField); System.out.println(new VariablesInJava().instanceField); } } ``` 掌握 Java 中的[靜態變量,以了解它與實例變量的不同之處。](https://javabeginnerstutorial.com/core-java-tutorial/java-static-keyword/) ### 參考文獻 * [官方文檔](https://docs.oracle.com/javase/tutorial/java/javaOO/classvars.html) * 靜態變量與實例變量
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看