{"id":830,"date":"2022-10-10T22:43:14","date_gmt":"2022-10-10T14:43:14","guid":{"rendered":"https:\/\/qaqaq.top\/?p=830"},"modified":"2022-11-27T12:39:54","modified_gmt":"2022-11-27T04:39:54","slug":"%e9%9d%a2%e5%90%91%e5%af%b9%e8%b1%a1%e4%b8%8b-%e9%9d%99%e6%80%81%e5%8f%98%e9%87%8f%e4%b8%8e%e5%ae%9e%e4%be%8b%e5%8f%98%e9%87%8f%e7%9a%84%e5%af%b9%e6%af%94%e3%80%81static%e4%bf%ae%e9%a5%b0%e5%b1%9e-2","status":"publish","type":"post","link":"https:\/\/qaqaq.top\/?p=830","title":{"rendered":"\u9762\u5411\u5bf9\u8c61(\u4e0b)-\u9759\u6001\u53d8\u91cf\u4e0e\u5b9e\u4f8b\u53d8\u91cf\u7684\u5bf9\u6bd4\u3001static\u4fee\u9970\u5c5e\u6027\u7684\u5176\u5b83\u8bf4\u660e\u3001static\u4fee\u9970\u65b9\u6cd5\u3001\u5c5e\u6027\u6216\u65b9\u6cd5\u662f\u5426\u5e94\u8be5static\u7684\u7ecf\u9a8c\u4e4b\u8c08"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>package top.qaqaq.java.P316;\r\n\/*\r\n * static\u5173\u952e\u5b57\u7684\u4f7f\u7528\r\n * \r\n * 1. static\uff1a\u9759\u6001\u7684\r\n * 2. static\uff1a\u53ef\u4ee5\u7528\u6765\u4fee\u9970\uff1a\u5c5e\u6027\u3001\u65b9\u6cd5\u3001\u4ee3\u7801\u5757\u3001\u5185\u90e8\u7c7b\r\n * \r\n * 3. \u4f7f\u7528static\u4fee\u9970\u5c5e\u6027\uff1a\u9759\u6001\u53d8\u91cf\uff08\u6216\u7c7b\u53d8\u91cf\uff09\r\n * \t\t3.1 \u5c5e\u6027\uff1a\u6309\u662f\u5426\u4f7f\u7528static\u4fee\u9970\uff0c\u53c8\u5206\u4e3a\uff1a\u9759\u6001\u5c5e\u6027 vs \u975e\u9759\u6001\u5c5e\u6027(\u5b9e\u4f8b\u53d8\u91cf)\r\n * \t\t\t\u5b9e\u4f8b\u53d8\u91cf\uff1a\u6211\u4eec\u521b\u5efa\u4e86\u7c7b\u7684\u591a\u4e2a\u5bf9\u8c61\uff0c\u6bcf\u4e2a\u5bf9\u8c61\u90fd\u72ec\u7acb\u7684\u62e5\u6709\u4e00\u5957\u7c7b\u4e2d\u7684\u975e\u9759\u6001\u5c5e\u6027\u3002\u5f53\u4fee\u6539\u5176\u4e2d\u4e00\u4e2a\u5bf9\u8c61\u4e2d\u7684\r\n * \t\t\t\t\u975e\u9759\u6001\u5c5e\u6027\u65f6\uff0c\u4e0d\u4f1a\u5bfc\u81f4\u5176\u4ed6\u5bf9\u8c61\u4e2d\u540c\u6837\u7684\u5c5e\u6027\u503c\u7684\u4fee\u6539\u3002\r\n * \t\t\t\u9759\u6001\u53d8\u91cf\uff1a\u6211\u4eec\u521b\u5efa\u4e86\u7c7b\u7684\u591a\u4e2a\u5bf9\u8c61\uff0c\u591a\u4e2a\u5bf9\u8c61\u5171\u4eab\u540c\u4e00\u4e2a\u9759\u6001\u53d8\u91cf\u3002\u5f53\u901a\u8fc7\u67d0\u4e00\u4e2a\u5bf9\u8c61\u4fee\u6539\u9759\u6001\u53d8\u91cf\u65f6\uff0c\u4f1a\u5bfc\u81f4\r\n * \t\t\t\t\u5176\u4ed6\u5bf9\u8c61\u8c03\u7528\u6b64\u9759\u6001\u53d8\u91cf\u65f6\uff0c\u662f\u4fee\u6539\u8fc7\u4e86\u7684\u3002\r\n * \t\t3.2 static\u4fee\u9970\u5c5e\u6027\u7684\u5176\u4ed6\u8bf4\u660e\uff1a\r\n * \t\t\t\u2460 \u9759\u6001\u53d8\u91cf\u968f\u7740\u7c7b\u7684\u52a0\u8f7d\u800c\u52a0\u8f7d\u3002\u53ef\u4ee5\u901a\u8fc7\"\u7c7b.\u9759\u6001\u53d8\u91cf\"\u7684\u65b9\u5f0f\u8fdb\u884c\u8c03\u7528\r\n * \t\t\t\u2461 \u9759\u6001\u53d8\u91cf\u7684\u52a0\u8f7d\u8981\u65e9\u4e8e\u5bf9\u8c61\u7684\u521b\u5efa\u3002\r\n * \t\t\t\u2462 \u7531\u4e8e\u7c7b\u53ea\u4f1a\u52a0\u8f7d\u4e00\u6b21\uff0c\u5219\u9759\u6001\u53d8\u91cf\u5728\u5185\u5b58\u4e2d\u4e5f\u53ea\u4f1a\u5b58\u5728\u4e00\u4efd\uff1a\u5b58\u5728\u65b9\u6cd5\u533a\u7684\u9759\u6001\u57df\u4e2d\u3002\r\n * \r\n * \t\t\t\u2463 \t\t\u7c7b\u53d8\u91cf\t\t\u5b9e\u4f8b\u53d8\u91cf\r\n * \t\t\t\u7c7b\t\tyes\t\t\tno\t\t\t\r\n * \t\t\t\u5bf9\u8c61\t\tyes\t\t\tyes\r\n * \r\n * \t\t3.3 \u9759\u6001\u5c5e\u6027\u4e3e\u4f8b\uff1aSystem.out; Math.PI\r\n * \r\n * 4. \u4f7f\u7528static\u4fee\u9970\u65b9\u6cd5\uff1a\u9759\u6001\u65b9\u6cd5\r\n * \t\t\u2460 \u968f\u7740\u7c7b\u7684\u52a0\u8f7d\u800c\u52a0\u8f7d\uff0c\u53ef\u4ee5\u901a\u8fc7\"\u7c7b.\u9759\u6001\u65b9\u6cd5\"\u7684\u65b9\u5f0f\u8fdb\u884c\u8c03\u7528\r\n * \t\t\u2461 \t\t\t\t\u9759\u6001\u65b9\u6cd5\t\t\u975e\u9759\u6001\u65b9\u6cd5\r\n * \t\t\t\t\u7c7b\t\tyes\t\t\tno\r\n * \t\t\t\t\u5bf9\u8c61\t\tyes\t\t\tyes\r\n * \t\t\u2462 \u9759\u6001\u65b9\u6cd5\u4e2d\uff0c\u53ea\u80fd\u8c03\u7528\u9759\u6001\u7684\u65b9\u6cd5\u6216\u5c5e\u6027\r\n * \t\t  \u975e\u9759\u6001\u65b9\u6cd5\u4e2d\uff0c\u65e2\u53ef\u4ee5\u8c03\u7528\u975e\u9759\u6001\u7684\u65b9\u6cd5\u6216\u5c5e\u6027\uff0c\u4e5f\u53ef\u4ee5\u8c03\u7528\u9759\u6001\u7684\u65b9\u6cd5\u6216\u5c5e\u6027\r\n * \r\n * 5. static\u6ce8\u610f\u70b9\uff1a\r\n * \t\t5.1 \u5728\u9759\u6001\u7684\u65b9\u6cd5\u5185\uff0c\u4e0d\u80fd\u4f7f\u7528this\u5173\u952e\u5b57\u3001super\u5173\u952e\u5b57\r\n * \t\t5.2 \u5173\u4e8e\u9759\u6001\u5c5e\u6027\u548c\u9759\u6001\u65b9\u6cd5\u7684\u4f7f\u7528\uff0c\u5927\u5bb6\u90fd\u4ece\u751f\u547d\u5468\u671f\u7684\u89d2\u5ea6\u53bb\u7406\u89e3\u3002\r\n * \r\n * 6. \u5f00\u53d1\u4e2d\uff0c\u5982\u4f55\u786e\u5b9a\u4e00\u4e2a\u5c5e\u6027\u662f\u5426\u8981\u58f0\u660e\u4e3astatic\u7684\uff1f\r\n * \t\t> \u5c5e\u6027\u662f\u53ef\u4ee5\u88ab\u591a\u4e2a\u5bf9\u8c61\u6240\u5171\u4eab\u7684\uff0c\u4e0d\u4f1a\u968f\u7740\u5bf9\u8c61\u7684\u4e0d\u540c\u800c\u4e0d\u540c\u7684\u3002\r\n * \t\t> \u7c7b\u4e2d\u7684\u5e38\u91cf\u4e5f\u5e38\u5e38\u58f0\u660e\u4e3astatic\r\n * \r\n * \t  \u5f00\u53d1\u4e2d\uff0c\u5982\u4f55\u786e\u5b9a\u4e00\u4e2a\u65b9\u6cd5\u662f\u5426\u8981\u58f0\u660e\u4e3astatic\u7684\uff1f\r\n * \t\t> \u64cd\u4f5c\u9759\u6001\u5c5e\u6027\u7684\u65b9\u6cd5\uff0c\u901a\u5e38\u8bbe\u7f6e\u4e3astatic\u7684\r\n * \t\t> \u5de5\u5177\u7c7b\u4e2d\u7684\u65b9\u6cd5\uff0c\u4e60\u60ef\u4e0a\u58f0\u660e\u4e3astatic\u7684\u3002\u6bd4\u5982\uff1aMath\u3001Arrays\u3001Collections\r\n *\/\r\npublic class StaticTest {\r\n\r\n\tpublic static void main(String&#91;] args) {\r\n\t\t\r\n\t\tChinese.nation = \"\u4e2d\u56fd\";\r\n\t\t\r\n\t\tChinese c1 = new Chinese();\r\n\t\tc1.name = \"\u59da\u660e\";\r\n\t\tc1.age = 40;\r\n\t\tc1.nation = \"CHN\";\r\n\t\t\r\n\t\tChinese c2 = new Chinese();\r\n\t\tc2.name = \"\u9a6c\u9f99\";\r\n\t\tc2.age = 30;\r\n\t\tc2.nation = \"CHINA\";\r\n\t\t\r\n\t\tSystem.out.println(c1.nation);\r\n\t\t\r\n\t\t\/\/\u7f16\u8bd1\u4e0d\u901a\u8fc7\r\n\/\/\t\tChinese.name = \"\u5f20\u7ee7\u79d1\";\r\n\t\t\t\r\n\t\tc1.eat();\r\n\t\t\r\n\t\tChinese.show();\r\n\t\t\r\n\t\t\/\/\u7f16\u8bd1\u4e0d\u901a\u8fc7\r\n\/\/\t\tChinese.eat();\r\n\/\/\t\tChinese.info();\r\n\t}\r\n}\r\n\r\n\/\/\u4e2d\u56fd\u4eba\r\nclass Chinese{\r\n\t\r\n\tString name;\r\n\tint age;\r\n\tstatic String nation;\r\n\t\r\n\tpublic void eat() {\r\n\t\tSystem.out.println(\"\u4e2d\u56fd\u4eba\u5403\u4e2d\u9910\");\r\n\t\t\/\/\u8c03\u7528\u975e\u9759\u6001\u7ed3\u6784\r\n\t\tthis.info();\r\n\t\tSystem.out.println(\"name :\" + name);\r\n\t\t\/\/\u8c03\u7528\u9759\u6001\u7ed3\u6784\r\n\t\twalk();\r\n\t\tSystem.out.println(\"nation :\" + nation);\r\n\t}\r\n\t\r\n\tpublic static void show() {\r\n\t\tSystem.out.println(\"\u6211\u662f\u4e00\u4e2a\u4e2d\u56fd\u4eba\uff01\");\r\n\t\t\/\/\u4e0d\u80fd\u8c03\u7528\u975e\u9759\u6001\u7684\u7ed3\u6784\r\n\/\/\t\teat();\r\n\/\/\t\tname = \"Tom\";\r\n\t\t\/\/\u53ef\u4ee5\u8c03\u7528\u9759\u6001\u7684\u7ed3\u6784\r\n\t\tSystem.out.println(Chinese.nation);\r\n\t\twalk();\r\n\t}\r\n\t\r\n\tpublic void info() {\r\n\t\tSystem.out.println(\"name :\" + name + \",age :\" + age);\r\n\t}\r\n\t\r\n\tpublic static void walk() {\r\n\t\t\r\n\t}\r\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[46],"class_list":["post-830","post","type-post","status-publish","format-standard","hentry","category-java-code","tag-java"],"_links":{"self":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/830"}],"collection":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=830"}],"version-history":[{"count":1,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/830\/revisions"}],"predecessor-version":[{"id":831,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/830\/revisions\/831"}],"wp:attachment":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=830"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=830"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=830"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}