{"id":39457,"date":"2024-11-26T15:51:01","date_gmt":"2024-11-26T07:51:01","guid":{"rendered":"https:\/\/fwq.ai\/blog\/39457\/"},"modified":"2024-11-26T15:51:01","modified_gmt":"2024-11-26T07:51:01","slug":"%e6%80%8e%e4%b9%88%e5%88%9b%e5%bb%ba%e4%b8%80%e4%b8%aa%e5%af%b9%e8%b1%a1%e6%95%b0%e7%bb%84-java","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/39457\/","title":{"rendered":"\u600e\u4e48\u521b\u5efa\u4e00\u4e2a\u5bf9\u8c61\u6570\u7ec4 java"},"content":{"rendered":"<blockquote><p>\n  \u5728 java \u4e2d\u521b\u5efa\u5bf9\u8c61\u6570\u7ec4\u7684\u6b65\u9aa4\u5305\u62ec\uff1a\u58f0\u660e\u6570\u7ec4\u7c7b\u578b\u3002\u4f7f\u7528 new \u5173\u952e\u5b57\u521b\u5efa\u6570\u7ec4\u5bf9\u8c61\u3002\u4f7f\u7528\u7d22\u5f15\u53f7\u8bbf\u95ee\u6570\u7ec4\u5143\u7d20\u3002\u4f7f\u7528\u7d22\u5f15\u53f7\u8bbe\u7f6e\u6570\u7ec4\u5143\u7d20\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/16\/2024111611094459162.jpg\" class=\"aligncenter\" title=\"\u600e\u4e48\u521b\u5efa\u4e00\u4e2a\u5bf9\u8c61\u6570\u7ec4 java\u63d2\u56fe\" alt=\"\u600e\u4e48\u521b\u5efa\u4e00\u4e2a\u5bf9\u8c61\u6570\u7ec4 java\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5728 Java \u4e2d\u521b\u5efa\u5bf9\u8c61\u6570\u7ec4<\/strong><\/p>\n<p>\u5728 Java \u4e2d\u521b\u5efa\u5bf9\u8c61\u6570\u7ec4\u7684\u8fc7\u7a0b\u5982\u4e0b\uff1a<\/p>\n<p><strong>1. \u58f0\u660e\u6570\u7ec4\u7c7b\u578b<\/strong><\/p>\n<p>\u9996\u5148\uff0c\u9700\u8981\u58f0\u660e\u6570\u7ec4\u7684\u7c7b\u578b\uff0c\u5373\u6570\u7ec4\u4e2d\u5b58\u50a8\u7684\u5bf9\u8c61\u7c7b\u578b\u3002\u4f8b\u5982\uff0c\u8981\u521b\u5efa\u4e00\u4e2a\u5b58\u50a8 Person \u5bf9\u8c61\u7684\u6570\u7ec4\uff0c\u53ef\u4ee5\u58f0\u660e\u5982\u4e0b\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>Person[] persons;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u521b\u5efa\u6570\u7ec4\u5bf9\u8c61<\/strong><\/p>\n<p>\u4f7f\u7528 new \u5173\u952e\u5b57\u521b\u5efa\u6570\u7ec4\u5bf9\u8c61\uff0c\u5e76\u6307\u5b9a\u6570\u7ec4\u7684\u5927\u5c0f\u3002\u4f8b\u5982\uff0c\u8981\u521b\u5efa\u4e00\u4e2a\u53ef\u4ee5\u5bb9\u7eb3 10 \u4e2a Person \u5bf9\u8c61\u7684\u6570\u7ec4\uff0c\u53ef\u4ee5\u8fd9\u6837\u5199\uff1a<\/p>\n<pre>persons = new Person[10];<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>3. \u8bbf\u95ee\u6570\u7ec4\u5143\u7d20<\/strong><\/p>\n<p>\u53ef\u4ee5\u4f7f\u7528\u7d22\u5f15\u53f7\u6765\u8bbf\u95ee\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u3002\u4f8b\u5982\uff0c\u4ee5\u4e0b\u4ee3\u7801\u8bbf\u95ee\u6570\u7ec4\u4e2d\u7b2c\u4e00\u4e2a Person \u5bf9\u8c61\uff1a<\/p>\n<pre>Person firstPerson = persons[0];<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>4. \u8bbe\u7f6e\u6570\u7ec4\u5143\u7d20<\/strong><\/p>\n<p>\u540c\u6837\u53ef\u4ee5\u4f7f\u7528\u7d22\u5f15\u53f7\u6765\u8bbe\u7f6e\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u3002\u4f8b\u5982\uff0c\u4ee5\u4e0b\u4ee3\u7801\u5c06\u6570\u7ec4\u4e2d\u7b2c\u4e00\u4e2a Person \u5bf9\u8c61\u8bbe\u7f6e\u4e3a John Doe\uff1a<\/p>\n<pre>persons[0] = new Person(\"John Doe\");<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u793a\u4f8b\u4ee3\u7801<\/strong><\/p>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u5b8c\u6574\u7684 Java \u4ee3\u7801\u793a\u4f8b\uff0c\u6f14\u793a\u5982\u4f55\u521b\u5efa\u548c\u4f7f\u7528\u5bf9\u8c61\u6570\u7ec4\uff1a<\/p>\n<pre>public class ObjectArrayExample {\n\n    public static void main(String[] args) {\n        \/\/ \u58f0\u660e\u4e00\u4e2a\u53ef\u4ee5\u5bb9\u7eb3 10 \u4e2a Person \u5bf9\u8c61\u7684\u6570\u7ec4\n        Person[] persons = new Person[10];\n\n        \/\/ \u521b\u5efa\u4e00\u4e2a Person \u5bf9\u8c61\u5e76\u5c06\u5176\u6dfb\u52a0\u5230\u6570\u7ec4\u4e2d\n        Person person1 = new Person(\"John Doe\");\n        persons[0] = person1;\n\n        \/\/ \u83b7\u53d6\u6570\u7ec4\u4e2d\u7b2c\u4e00\u4e2a Person \u5bf9\u8c61\n        Person firstPerson = persons[0];\n\n        \/\/ \u6253\u5370\u7b2c\u4e00\u4e2a Person \u5bf9\u8c61\u7684\u59d3\u540d\n        System.out.println(firstPerson.getName()); \/\/ \u8f93\u51fa\uff1aJohn Doe\n    }\n}\n\nclass Person {\n\n    private String name;\n\n    public Person(String name) {\n        this.name = name;\n    }\n\n    public String getName() {\n        return name;\n    }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u521b\u5efa\u4e00\u4e2a\u5bf9\u8c61\u6570\u7ec4 java\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 java \u4e2d\u521b\u5efa\u5bf9\u8c61\u6570\u7ec4\u7684\u6b65\u9aa4\u5305\u62ec\uff1a\u58f0\u660e\u6570\u7ec4\u7c7b\u578b\u3002\u4f7f\u7528 new \u5173\u952e\u5b57\u521b\u5efa\u6570\u7ec4\u5bf9\u8c61\u3002\u4f7f\u7528\u7d22\u5f15\u53f7\u8bbf\u95ee\u6570\u7ec4\u5143\u7d20\u3002\u4f7f\u7528\u7d22\u5f15\u53f7\u8bbe\u7f6e\u6570\u7ec4\u5143\u7d20\u3002 \u5982\u4f55\u5728 Java \u4e2d\u521b\u5efa\u5bf9\u8c61\u6570\u7ec4 \u5728 Java \u4e2d\u521b\u5efa\u5bf9\u8c61\u6570\u7ec4\u7684\u8fc7\u7a0b\u5982\u4e0b\uff1a 1. \u58f0\u660e\u6570\u7ec4\u7c7b\u578b \u9996\u5148\uff0c\u9700\u8981\u58f0\u660e\u6570\u7ec4\u7684\u7c7b\u578b\uff0c\u5373\u6570\u7ec4\u4e2d\u5b58\u50a8\u7684\u5bf9\u8c61\u7c7b\u578b\u3002\u4f8b\u5982\uff0c\u8981\u521b\u5efa\u4e00\u4e2a\u5b58\u50a8 Person \u5bf9\u8c61\u7684\u6570\u7ec4\uff0c\u53ef\u4ee5\u58f0\u660e\u5982\u4e0b\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b Person[] persons; \u767b\u5f55\u540e\u590d\u5236 2. \u521b\u5efa\u6570\u7ec4\u5bf9\u8c61 \u4f7f\u7528 new \u5173\u952e\u5b57\u521b\u5efa\u6570\u7ec4\u5bf9\u8c61\uff0c\u5e76\u6307\u5b9a\u6570\u7ec4\u7684\u5927\u5c0f\u3002\u4f8b\u5982\uff0c\u8981\u521b\u5efa\u4e00\u4e2a\u53ef\u4ee5\u5bb9\u7eb3 10 \u4e2a Person \u5bf9\u8c61\u7684\u6570\u7ec4\uff0c\u53ef\u4ee5\u8fd9\u6837\u5199\uff1a persons = new Person[10]; \u767b\u5f55\u540e\u590d\u5236 3. \u8bbf\u95ee\u6570\u7ec4\u5143\u7d20 \u53ef\u4ee5\u4f7f\u7528\u7d22\u5f15\u53f7\u6765\u8bbf\u95ee\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u3002\u4f8b\u5982\uff0c\u4ee5\u4e0b\u4ee3\u7801\u8bbf\u95ee\u6570\u7ec4\u4e2d\u7b2c\u4e00\u4e2a Person \u5bf9\u8c61\uff1a Person firstPerson = persons[0]; \u767b\u5f55\u540e\u590d\u5236 4. \u8bbe\u7f6e\u6570\u7ec4\u5143\u7d20 \u540c\u6837\u53ef\u4ee5\u4f7f\u7528\u7d22\u5f15\u53f7\u6765\u8bbe\u7f6e\u6570\u7ec4\u4e2d\u7684\u5143\u7d20\u3002\u4f8b\u5982\uff0c\u4ee5\u4e0b\u4ee3\u7801\u5c06\u6570\u7ec4\u4e2d\u7b2c\u4e00\u4e2a Person \u5bf9\u8c61\u8bbe\u7f6e\u4e3a John Doe\uff1a persons[0] = new Person(&#8220;John [&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-39457","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/39457","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=39457"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/39457\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=39457"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=39457"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=39457"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}