{"id":474,"date":"2019-02-14T23:27:35","date_gmt":"2019-02-14T15:27:35","guid":{"rendered":"http:\/\/www.eait.co\/?p=474"},"modified":"2019-04-05T12:32:51","modified_gmt":"2019-04-05T04:32:51","slug":"java%e6%9e%84%e9%80%a0%e6%96%b9%e6%b3%95%e7%9a%84%e7%a7%81%e6%9c%89-%e4%ba%a7%e7%94%9f%e6%9c%ac%e7%b1%bb%e4%b8%ad%e7%9a%84%e5%ae%9e%e4%be%8b%e5%8c%96%e5%af%b9%e8%b1%a1","status":"publish","type":"post","link":"https:\/\/notes.coremix.net\/?p=474","title":{"rendered":"java\u6784\u9020\u65b9\u6cd5\u7684\u79c1\u6709\u2014\u2014\u4ea7\u751f\u672c\u7c7b\u4e2d\u7684\u5b9e\u4f8b\u5316\u5bf9\u8c61\uff08\u7cbe\u534e\uff09"},"content":{"rendered":"<pre>\/**\r\n * Created by xabcd on 2019\/2\/14.\r\n *\/\r\npublic class testprivate2\r\n{\r\n    String name;\r\n    \/\/\u672c\u7c7b\u4e2d\u58f0\u660e\u4e00\u4e2aPerson\u5bf9\u8c61p\uff0c\u4f7f\u7528final\u6807\u8bb0\uff0c\u8868\u793a\u4e0d\u80fd\u518d\u91cd\u65b0\u5b9e\u4f8b\u5316\r\n    private static final testprivate2 p = new testprivate2();\r\n<span style=\"color: #ff0000;\">\/\/\u4e0a\u9762\u751f\u6210\u4e00\u4e2a\u5b9e\u4f8b\u5316\u5bf9\u8c61\uff0c\u4e14\u88ab\u6807\u8bc6\u9759\u6001\uff0c\u4e14final\u8868\u793a\u5bf9\u8c61p\u65e0\u6cd5\u91cd\u65b0\u5b9e\u4f8b\u5316<\/span>\r\n    private testprivate2()<span style=\"color: #ff0000;\">\/\/\u5c01\u88c5 \u5916\u90e8\u65e0\u6cd5\u8fdb\u884c\u5b9e\u4f8b\u5316<\/span>\r\n    {\r\n        name = \"\u5f20\u4e09\";\r\n    }\r\n    public static testprivate2 getP()\r\n    {\r\n        return p;\r\n    }\r\n    public static void main(String args[])\r\n    {\r\n        \/\/\u58f0\u660e\u4e00\u4e2atestprivate2\u7c7b\u7684\u5bf9\u8c61\r\n        testprivate2 p = null;<span style=\"color: #ff0000;\">\/\/\u58f0\u660e\u5bf9\u8c61\u4f46\u662f\u672a\u5b9e\u4f8b\u5316<\/span>\r\n        p = testprivate2.getP();<span style=\"color: #ff0000;\">\/\/\u8c03\u7528\u7c7b\u4e2d\u7684getP\uff08\uff09\u65b9\u6cd5\uff0c\u6b64\u65b9\u6cd5\u8fd4\u56de\u7c7b\u7684\u5b9e\u4f8b\u5316\u5bf9\u8c61<\/span>\r\n        System.out.println(p.name);\r\n    }\r\n}\r\n\r\n\u7ed3\u679c\uff1a\u5f20\u4e09\r\n\r\n\r\n<\/pre>\n<p>\u7b2c 6 \uff5e 9private testprivate2\uff08\uff09 \u884c\u5c06 Person \u7c7b \u7684 \u6784\u9020 \u65b9\u6cd5 \u5c01\u88c5 \u8d77\u6765\uff0c \u5916\u90e8 \u65e0\u6cd5 \u901a\u8fc7 \u5176 \u6784\u9020 \u65b9\u6cd5 \u4ea7\u751f \u5b9e\u4f8b \u5316 \u5bf9\u8c61\u3002 \u7b2c 5 \u884c \u58f0\u660e \u4e00\u4e2a Person \u7c7b \u7684 \u5b9e\u4f8b \u5316 \u5bf9\u8c61\uff0c \u6b64 \u5bf9\u8c61 \u662f\u5728 Person \u7c7b \u5185\u90e8 \u5b9e\u4f8b \u5316\uff0c \u6240\u4ee5 \u53ef\u4ee5 \u8c03\u7528 \u79c1\u6709 \u6784\u9020 \u65b9\u6cd5\u3002 \u53e6\u5916\uff0c \u6b64 \u5bf9\u8c61 \u88ab \u6807\u8bc6 \u4e3a static \u7c7b\u578b\uff0c \u8868\u793a \u4e3a \u4e00 \u9759\u6001 \u5c5e\u6027\uff0c \u540c\u65f6 \u6b64 \u5bf9 \u8c61\u88ab \u79c1\u6709\u5316\uff0c \u53e6\u5916 \u5728 \u58f0\u660e Person \u5bf9\u8c61 \u7684 \u65f6\u5019 \u52a0\u4e0a \u4e86 \u4e00\u4e2a final \u5173\u952e\u5b57\uff0c \u6b64 \u5173\u952e\u5b57 \u8868\u793a Person \u7684 \u5bf9\u8c61 p \u4e0d\u80fd \u88ab \u91cd\u65b0 \u5b9e\u4f8b \u5316\uff08 \u5173\u4e8e final\uff0c \u8bf7\u53c2\u9605 \u7b2c 11 \u7ae0 \u4e2d\u7684 11. 3 \u4e00\u8282\uff09\u3002 \u7b2c 21 \u884c \u58f0\u660e \u4e00\u4e2a Person \u7c7b \u7684 \u5bf9\u8c61 p\uff0c \u4f46\u672a \u5b9e\u4f8b \u5316\u3002 \u7b2c 22 \u884c \u8c03\u7528 Person \u7c7b \u4e2d\u7684 getP() \u65b9\u6cd5\uff0c \u6b64 \u65b9\u6cd5 \u8fd4\u56de Person \u7c7b \u7684 \u5b9e\u4f8b \u5316 \u5bf9\u8c61\u3002 \u3010\u8303\u4f8b \u5206\u6790\u3011 \u4ece \u7a0b\u5e8f \u4e2d \u53ef\u4ee5 \u770b\u51fa\uff0c \u65e0\u8bba \u5728 Person \u7c7b \u7684 \u5916\u90e8 \u58f0\u660e \u591a\u5c11 \u4e2a \u5bf9\u8c61\uff0c \u6700\u7ec8 \u5f97\u5230 \u7684 \u90fd\u662f \u540c\u4e00\u4e2a \u5f15\u7528\uff0c \u56e0\u4e3a \u6b64\u7c7b \u53ea\u80fd \u4ea7\u751f \u4e00\u4e2a \u5b9e\u4f8b \u5bf9\u8c61\uff0c \u8fd9\u79cd \u505a\u6cd5 \u5728 \u8bbe\u8ba1 \u6a21\u5f0f \u4e2d \u88ab\u79f0\u4e3a \u5355 \u6001 \u6a21\u5f0f\u3002 \u800c \u6240\u8c13 \u8bbe\u8ba1 \u6a21\u5f0f \u4e5f\u5c31 \u662f\u5728 \u5927\u91cf \u7684 \u5b9e\u8df5\u4e2d \u603b\u7ed3 \u548c \u7406\u8bba\u5316 \u4e4b\u540e \u4f18\u9009 \u7684 \u4ee3\u7801 \u7ed3\u6784\u3001 \u7f16\u7a0b \u98ce\u683c \u4ee5\u53ca \u89e3\u51b3\u95ee\u9898 \u7684 \u601d\u8003 \u65b9\u5f0f\u3002 \u6709\u5174\u8da3 \u7684 \u8bfb\u8005 \u53ef\u4ee5 \u7814\u7a76 \u4e00\u4e0b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\/** * Created by xabcd on 2019\/2\/14. *\/ public class te [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24,1],"tags":[],"class_list":["post-474","post","type-post","status-publish","format-standard","hentry","category-base_code","category-uncategorized"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/notes.coremix.net\/index.php?rest_route=\/wp\/v2\/posts\/474","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/notes.coremix.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/notes.coremix.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/notes.coremix.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/notes.coremix.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=474"}],"version-history":[{"count":6,"href":"https:\/\/notes.coremix.net\/index.php?rest_route=\/wp\/v2\/posts\/474\/revisions"}],"predecessor-version":[{"id":480,"href":"https:\/\/notes.coremix.net\/index.php?rest_route=\/wp\/v2\/posts\/474\/revisions\/480"}],"wp:attachment":[{"href":"https:\/\/notes.coremix.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=474"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/notes.coremix.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=474"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/notes.coremix.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=474"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}