{"id":64255,"date":"2025-05-03T17:55:15","date_gmt":"2025-05-03T09:55:15","guid":{"rendered":"https:\/\/fwq.ai\/blog\/64255\/"},"modified":"2025-05-03T17:55:15","modified_gmt":"2025-05-03T09:55:15","slug":"java%e9%9d%99%e6%80%81%e5%ad%97%e7%ac%a6%e4%b8%b2%e6%95%b0%e7%bb%84%e6%80%8e%e4%b9%88%e5%88%9b%e5%bb%ba-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/64255\/","title":{"rendered":"java\u9759\u6001\u5b57\u7b26\u4e32\u6570\u7ec4\u600e\u4e48\u521b\u5efa"},"content":{"rendered":"<blockquote><p>\n  \u8981\u521b\u5efa\u9759\u6001\u5b57\u7b26\u4e32\u6570\u7ec4\uff0c\u53ef\u4ee5\u5728\u7c7b\u58f0\u660e\u4e2d\u4f7f\u7528static\u5173\u952e\u5b57\uff0c\u7136\u540e\u662f\u6570\u636e\u7c7b\u578b\u548c\u6570\u7ec4\u540d\u3002\u9759\u6001\u6570\u7ec4\u662f\u7c7b\u7ea7\u522b\u7684\uff0c\u53ef\u4ee5\u5728\u6240\u6709\u5b9e\u4f8b\u548c\u65b9\u6cd5\u4e2d\u8bbf\u95ee\uff0c\u53ef\u4ee5\u5728\u9759\u6001\u5757\u6216\u6784\u9020\u51fd\u6570\u4e2d\u521d\u59cb\u5316\u5143\u7d20\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/03\/2024110302065414035.jpg\" class=\"aligncenter\" title=\"java\u9759\u6001\u5b57\u7b26\u4e32\u6570\u7ec4\u600e\u4e48\u521b\u5efa\u63d2\u56fe\" alt=\"java\u9759\u6001\u5b57\u7b26\u4e32\u6570\u7ec4\u600e\u4e48\u521b\u5efa\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5728 Java \u4e2d\u521b\u5efa\u9759\u6001<\/strong><\/p>\n<p><strong>\u56de\u7b54\uff1a<\/strong><br \/>\u8981\u521b\u5efa\u9759\u6001\u5b57\u7b26\u4e32\u6570\u7ec4\uff0c\u53ef\u4ee5\u5728\u7c7b\u58f0\u660e\u4e2d\u4f7f\u7528 static \u5173\u952e\u5b57\uff0c\u540e\u8ddf\u6570\u636e\u7c7b\u578b\u548c\u6570\u7ec4\u540d\u3002<\/p>\n<p><strong>\u8be6\u7ec6\u8bf4\u660e\uff1a<\/strong><\/p>\n<pre>public class MyClass {\n\n    \/\/ \u58f0\u660e\u9759\u6001\u5b57\u7b26\u4e32\u6570\u7ec4\n    private static String[] names;\n\n    \/\/ \u5728\u9759\u6001\u5757\u4e2d\u521d\u59cb\u5316\u6570\u7ec4\n    static {\n        names = new String[] {\"John\", \"Mary\", \"Bob\"};\n    }\n\n    \/\/ ... \u5176\u4ed6\u7c7b\u65b9\u6cd5\u548c\u6210\u5458\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>public class Main {\n\n    public static void main(String[] args) {\n\n        \/\/ \u8bbf\u95ee\u9759\u6001\u5b57\u7b26\u4e32\u6570\u7ec4\n        System.out.println(MyClass.names[0]); \/\/ \u8f93\u51fa\uff1aJohn\n    }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<ul>\n<li>\u9759\u6001\u6570\u7ec4\u662f\u7c7b\u7ea7\u522b\u7684\uff0c\u53ef\u4ee5\u5728\u7c7b\u7684\u6240\u6709\u5b9e\u4f8b\u548c\u65b9\u6cd5\u4e2d\u8bbf\u95ee\u3002<\/li>\n<li>\u9759\u6001\u5757\u7528\u4e8e\u5728\u7c7b\u52a0\u8f7d\u65f6\u521d\u59cb\u5316\u6570\u7ec4\u3002<\/li>\n<li>\u6570\u7ec4\u5143\u7d20\u53ef\u4ee5\u5728\u9759\u6001\u5757\u6216\u6784\u9020\u51fd\u6570\u4e2d\u8fdb\u884c\u521d\u59cb\u5316\u3002<\/li>\n<li>static \u5173\u952e\u5b57\u8fd8\u53ef\u4ee5\u7528\u4e8e\u58f0\u660e\u5176\u4ed6\u9759\u6001\u6210\u5458\uff0c\u4f8b\u5982\u9759\u6001\u65b9\u6cd5\u548c\u9759\u6001\u53d8\u91cf\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u9759\u6001\u600e\u4e48\u521b\u5efa\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8IDCBABY\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8981\u521b\u5efa\u9759\u6001\u5b57\u7b26\u4e32\u6570\u7ec4\uff0c\u53ef\u4ee5\u5728\u7c7b\u58f0\u660e\u4e2d\u4f7f\u7528static\u5173\u952e\u5b57\uff0c\u7136\u540e\u662f\u6570\u636e\u7c7b\u578b\u548c\u6570\u7ec4\u540d\u3002\u9759\u6001\u6570\u7ec4\u662f\u7c7b\u7ea7\u522b\u7684\uff0c\u53ef\u4ee5\u5728\u6240\u6709\u5b9e\u4f8b\u548c\u65b9\u6cd5\u4e2d\u8bbf\u95ee\uff0c\u53ef\u4ee5\u5728\u9759\u6001\u5757\u6216\u6784\u9020\u51fd\u6570\u4e2d\u521d\u59cb\u5316\u5143\u7d20\u3002 \u5982\u4f55\u5728 Java \u4e2d\u521b\u5efa\u9759\u6001 \u56de\u7b54\uff1a\u8981\u521b\u5efa\u9759\u6001\u5b57\u7b26\u4e32\u6570\u7ec4\uff0c\u53ef\u4ee5\u5728\u7c7b\u58f0\u660e\u4e2d\u4f7f\u7528 static \u5173\u952e\u5b57\uff0c\u540e\u8ddf\u6570\u636e\u7c7b\u578b\u548c\u6570\u7ec4\u540d\u3002 \u8be6\u7ec6\u8bf4\u660e\uff1a public class MyClass { \/\/ \u58f0\u660e\u9759\u6001\u5b57\u7b26\u4e32\u6570\u7ec4 private static String[] names; \/\/ \u5728\u9759\u6001\u5757\u4e2d\u521d\u59cb\u5316\u6570\u7ec4 static { names = new String[] {&#8220;John&#8221;, &#8220;Mary&#8221;, &#8220;Bob&#8221;}; } \/\/ &#8230; \u5176\u4ed6\u7c7b\u65b9\u6cd5\u548c\u6210\u5458 } \u767b\u5f55\u540e\u590d\u5236 \u793a\u4f8b\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b public class Main { public static void main(String[] args) { \/\/ \u8bbf\u95ee\u9759\u6001\u5b57\u7b26\u4e32\u6570\u7ec4 System.out.println(MyClass.names[0]); \/\/ \u8f93\u51fa\uff1aJohn } } \u767b\u5f55\u540e\u590d\u5236 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-64255","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/64255","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=64255"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/64255\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=64255"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=64255"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=64255"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}