<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>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                ## 1.static和public都是修飾符,并列的沒有先后順序,先寫誰后寫誰都行 ## 2.在靜態方法中不能使用this關鍵字 ## 3.在靜態方法中不能訪問非靜態的方法 ## 4.在靜態方法中不能訪問非靜態的屬性 ## 5.非靜態的方法可以用對象名.方法名去調用 ## 6.靜態的方法可以用? 對象名.方法名去調用? 也可以 用? 類名.方法名 (推薦) 1】static可以修飾:屬性,方法,代碼塊,內部類。 【2】static修飾屬性; ~~~ package com.msb5; /** * @Auther: msb-zhaoss */ public class Test { //屬性: int id; static int sid; //這是一個main方法,是程序的入口: public static void main(String[] args) { //創建一個Test類的具體的對象 Test t1 = new Test(); t1.id = 10; t1.sid = 10; Test t2 = new Test(); t2.id = 20; t2.sid = 20; Test t3 = new Test(); t3.id = 30; t3.sid = 30; //讀取屬性的值: System.out.println(t1.id); System.out.println(t2.id); System.out.println(t3.id); System.out.println(t1.sid); System.out.println(t2.sid); System.out.println(t3.sid); } } ~~~ ## 內存分析: ![](https://img.kancloud.cn/8d/81/8d8197edeccb16fa0bfe89d4fa838d5c_1386x743.png) ## 一般官方的推薦訪問方式:可以通過類名.屬性名的方式去訪問: ## static修飾屬性總結: ## ## (1)在類加載的時候一起加載入方法區中的靜態域中 ## ## (2)先于對象存在 ## ## (3)訪問方式: 對象名.屬性名 ? ?類名.屬性名(推薦) static修飾屬性的應用場景:某些特定的數據想要在內存中共享,只有一塊 --》這個情況下,就可以用static修飾的屬性 ``` * package com.msb5; * /\*\* * \* @Auther: msb-zhaoss * \*/ * public class Demo { * ? ? int id; * ? ? static int sid; * ? ? public void a(){ * ? ? ? ? System.out.println(id); * ? ? ? ? System.out.println(sid); * ? ? ? ? System.out.println("------a"); * ? ? } * ? ? //1.static和public都是修飾符,并列的沒有先后順序,先寫誰后寫誰都行 * ? ? static public void b(){ * ? ? ? ? //System.out.println(this.id);//4.在靜態方法中不能使用this關鍵字 * ? ? ? ? //a();//3.在靜態方法中不能訪問非靜態的方法 * ? ? ? ? //System.out.println(id);//2.在靜態方法中不能訪問非靜態的屬性 * ? ? ? ? System.out.println(sid); * ? ? ? ? System.out.println("------b"); * ? ? } * ? ? //這是一個main方法,是程序的入口: * ? ? public static void main(String\[\] args) { * ? ? ? ? //5.非靜態的方法可以用對象名.方法名去調用 * ? ? ? ? Demo d = new Demo(); * ? ? ? ? d.a(); * ? ? ? ? //6.靜態的方法可以用? 對象名.方法名去調用? 也可以 用? 類名.方法名 (推薦) * ? ? ? ? Demo.b(); * ? ? ? ? d.b(); * ? ? ? ![](file:///C:/Users/ADMINI~1/AppData/Local/Temp/__nyf7_clip_images/image_623414b8_1a54.png) * ? ? } * } ``` 屬性: 靜態屬性 (類變量) 非靜態屬性(實例變量) 【3】static修飾方法;
                  <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>

                              哎呀哎呀视频在线观看