{"id":854,"date":"2022-10-11T22:26:26","date_gmt":"2022-10-11T14:26:26","guid":{"rendered":"https:\/\/qaqaq.top\/?p=854"},"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-%e7%b1%bb%e4%b8%ad%e4%bb%a3%e7%a0%81%e5%9d%97%e7%bb%93%e6%9e%84%e7%9a%84%e4%bd%bf%e7%94%a8","status":"publish","type":"post","link":"https:\/\/qaqaq.top\/?p=854","title":{"rendered":"\u9762\u5411\u5bf9\u8c61(\u4e0b)-\u7c7b\u4e2d\u4ee3\u7801\u5757\u7ed3\u6784\u7684\u4f7f\u7528"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>package top.qaqaq.java.P330;\r\n\/*\r\n * \u7c7b\u7684\u6210\u5458\u4e4b\u56db\uff1a\u4ee3\u7801\u5757\uff08\u6216\u521d\u59cb\u5316\u5757\uff09\r\n * \r\n * 1. \u4ee3\u7801\u5757\u7684\u4f5c\u7528\uff1a\u7528\u6765\u521d\u59cb\u5316\u7c7b\u3001\u5bf9\u8c61\r\n * 2. \u4ee3\u7801\u5757\u5982\u679c\u6709\u4fee\u9970\u7684\u8bdd\uff0c\u53ea\u80fd\u4f7f\u7528static.\r\n * 3. \u5206\u7c7b\uff1a\u9759\u6001\u4ee3\u7801\u5757 vs \u975e\u9759\u6001\u4ee3\u7801\u5757\r\n * \r\n * 4. \u9759\u6001\u4ee3\u7801\u5757\r\n * \t\t>\u5185\u90e8\u53ef\u4ee5\u6709\u8f93\u51fa\u8bed\u53e5\r\n * \t\t>\u968f\u7740\u7c7b\u7684\u52a0\u8f7d\u800c\u6267\u884c,\u800c\u4e14\u53ea\u6267\u884c\u4e00\u6b21\r\n * \t\t>\u4f5c\u7528\uff1a\u521d\u59cb\u5316\u7c7b\u7684\u4fe1\u606f\r\n * \t\t>\u5982\u679c\u4e00\u4e2a\u7c7b\u4e2d\u5b9a\u4e49\u4e86\u591a\u4e2a\u9759\u6001\u4ee3\u7801\u5757\uff0c\u5219\u6309\u7167\u58f0\u660e\u7684\u5148\u540e\u987a\u5e8f\u6267\u884c\r\n * \t\t>\u9759\u6001\u4ee3\u7801\u5757\u7684\u6267\u884c\u8981\u4f18\u5148\u4e8e\u975e\u9759\u6001\u4ee3\u7801\u5757\u7684\u6267\u884c\r\n * \t\t>\u9759\u6001\u4ee3\u7801\u5757\u5185\u53ea\u80fd\u8c03\u7528\u9759\u6001\u7684\u5c5e\u6027\u3001\u9759\u6001\u7684\u65b9\u6cd5\uff0c\u4e0d\u80fd\u8c03\u7528\u975e\u9759\u6001\u7684\u7ed3\u6784\r\n * \r\n * \r\n * 5. \u975e\u9759\u6001\u4ee3\u7801\u5757\r\n * \t\t>\u5185\u90e8\u53ef\u4ee5\u6709\u8f93\u51fa\u8bed\u53e5\r\n * \t\t>\u968f\u7740\u5bf9\u8c61\u7684\u521b\u5efa\u800c\u6267\u884c\r\n * \t\t>\u6bcf\u521b\u5efa\u4e00\u4e2a\u5bf9\u8c61\uff0c\u5c31\u6267\u884c\u4e00\u6b21\u975e\u9759\u6001\u4ee3\u7801\u5757\r\n * \t\t>\u4f5c\u7528\uff1a\u53ef\u4ee5\u5728\u521b\u5efa\u5bf9\u8c61\u65f6\uff0c\u5bf9\u5bf9\u8c61\u7684\u5c5e\u6027\u7b49\u8fdb\u884c\u521d\u59cb\u5316\r\n * \t\t>\u5982\u679c\u4e00\u4e2a\u7c7b\u4e2d\u5b9a\u4e49\u4e86\u591a\u4e2a\u975e\u9759\u6001\u4ee3\u7801\u5757\uff0c\u5219\u6309\u7167\u58f0\u660e\u7684\u5148\u540e\u987a\u5e8f\u6267\u884c\r\n * \t\t>\u975e\u9759\u6001\u4ee3\u7801\u5757\u5185\u53ef\u4ee5\u8c03\u7528\u9759\u6001\u7684\u5c5e\u6027\u3001\u9759\u6001\u7684\u65b9\u6cd5\uff0c\u6216\u975e\u9759\u6001\u7684\u5c5e\u6027\u3001\u975e\u9759\u6001\u7684\u65b9\u6cd5\r\n * \r\n *\/\r\npublic class BlockTest {\r\n\t\r\n\tpublic static void main(String&#91;] args) {\r\n\t\t\r\n\t\tString desc = Person.desc;\r\n\t\tSystem.out.println(desc);\r\n\t\t\r\n\t\tPerson p1 = new Person();\r\n\t\tPerson p2 = new Person();\r\n\t\tSystem.out.println(p1.age);\r\n\t\t\r\n\t\tPerson.info();\r\n\t}\r\n\r\n}\r\n\r\nclass Person{\r\n\t\/\/\u5c5e\u6027\r\n\tString name;\r\n\t\r\n\tint age;\r\n\t\r\n\tstatic String desc = \"\u6211\u662f\u4e00\u4e2a\u4eba\";\r\n\t\r\n\t\/\/\u6784\u9020\u5668\r\n\tpublic Person() {\r\n\t\t\r\n\t}\r\n\t\r\n\tpublic Person(String name, int age) {\r\n\t\tthis.name = name;\r\n\t\tthis.age = age;\t\r\n\t}\r\n\t\r\n\t\/\/\u975estatic\u7684\u4ee3\u7801\u5757\r\n\t{\r\n\t\tSystem.out.println(\"hello, block - 2\");\r\n\t}\r\n\t{\r\n\t\tSystem.out.println(\"hello, block - 1\");\r\n\t\t\/\/\u8c03\u7528\u975e\u9759\u6001\u7ed3\u6784\r\n\t\tage = 1;\r\n\t\teat();\r\n\t\t\/\/\u8c03\u7528\u9759\u6001\u7ed3\u6784\r\n\t\tdesc = \"\u6211\u662f\u4e00\u4e2a\u7231\u5b66\u4e60\u7684\u4eba1\";\r\n\t\tinfo();\r\n\t}\r\n\t\r\n\t\/\/static\u7684\u4ee3\u7801\u5757\r\n\tstatic{\r\n\t\tSystem.out.println(\"hello,static block-2\");\r\n\t}\r\n\tstatic{\r\n\t\tSystem.out.println(\"hello,static block-1\");\r\n\t\t\/\/\u8c03\u7528\u9759\u6001\u7ed3\u6784\r\n\t\tdesc = \"\u6211\u662f\u4e00\u4e2a\u7231\u5b66\u4e60\u7684\u4eba\";\r\n\t\tinfo();\r\n\t\t\/\/\u4e0d\u53ef\u4ee5\u8c03\u7528\u975e\u9759\u6001\u7ed3\u6784\r\n\/\/\t\teat();\r\n\/\/\t\tname = \"Tom\";\r\n\t}\r\n\t\r\n\t\/\/\u65b9\u6cd5\r\n\tpublic void eat() {\r\n\t\tSystem.out.println(\"\u5403\u996d\");\r\n\t}\r\n\r\n\t@Override\r\n\tpublic String toString() {\r\n\t\treturn \"Person &#91;name=\" + name + \", age=\" + age + \"]\";\r\n\t}\r\n\t\r\n\tpublic static void info() {\r\n\t\tSystem.out.println(\"\u6211\u662f\u4e00\u4e2a\u5feb\u4e50\u7684\u4eba\uff01\");\r\n\t}\r\n\t\r\n\t\r\n}\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-854","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\/854"}],"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=854"}],"version-history":[{"count":1,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/854\/revisions"}],"predecessor-version":[{"id":855,"href":"https:\/\/qaqaq.top\/index.php?rest_route=\/wp\/v2\/posts\/854\/revisions\/855"}],"wp:attachment":[{"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=854"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=854"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qaqaq.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=854"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}