{"id":66656,"date":"2025-05-03T13:16:20","date_gmt":"2025-05-03T05:16:20","guid":{"rendered":"https:\/\/fwq.ai\/blog\/66656\/"},"modified":"2025-05-03T13:16:20","modified_gmt":"2025-05-03T05:16:20","slug":"java%e6%80%8e%e4%b9%88%e8%b0%83%e7%94%a8%e7%b1%bb%e6%95%b0%e7%bb%84%e7%9a%84%e7%b1%bb%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/66656\/","title":{"rendered":"java\u600e\u4e48\u8c03\u7528\u7c7b\u6570\u7ec4\u7684\u7c7b\u65b9\u6cd5"},"content":{"rendered":"<blockquote><p>\n  \u8981\u8c03\u7528\u6570\u7ec4\u5143\u7d20\u7684\u7c7b\u65b9\u6cd5\uff0c\u9700\u8981\u6267\u884c\u4ee5\u4e0b\u6b65\u9aa4\uff1a\u5b9a\u4e49\u6570\u7ec4\u5e76\u521b\u5efa\u5b9e\u4f8b\uff1b\u4f7f\u7528\u4e2d\u62ec\u53f7 [] \u8bbf\u95ee\u6570\u7ec4\u5143\u7d20\uff1b\u8c03\u7528\u7c7b\u65b9\u6cd5\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/16\/2024111612034483417.jpg\" class=\"aligncenter\" title=\"java\u600e\u4e48\u8c03\u7528\u7c7b\u6570\u7ec4\u7684\u7c7b\u65b9\u6cd5\u63d2\u56fe\" alt=\"java\u600e\u4e48\u8c03\u7528\u7c7b\u6570\u7ec4\u7684\u7c7b\u65b9\u6cd5\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528 Java \u8c03\u7528\u6570\u7ec4\u5143\u7d20\u7684\u7c7b\u65b9\u6cd5<\/strong><\/p>\n<p>\u8981\u8c03\u7528\u6570\u7ec4\u5143\u7d20\u7684\u7c7b\u65b9\u6cd5\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<p><strong>1. \u5b9a\u4e49\u6570\u7ec4\u5e76\u521b\u5efa\u5b9e\u4f8b<\/strong><\/p>\n<p>\u9996\u5148\uff0c\u9700\u8981\u5b9a\u4e49\u4e00\u4e2a\u6570\u7ec4\u53d8\u91cf\u5e76\u521b\u5efa\u6570\u7ec4\u5143\u7d20\u7684\u5b9e\u4f8b\u3002\u4f8b\u5982\uff0c\u8981\u521b\u5efa\u4e00\u4e2a\u5305\u542b Person \u7c7b\u5bf9\u8c61\u7684\u6570\u7ec4\uff0c\u53ef\u4ee5\u6267\u884c\u4ee5\u4e0b\u64cd\u4f5c\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>Person[] people = new Person[3];\npeople[0] = new Person(\"John\", 25);\npeople[1] = new Person(\"Mary\", 30);\npeople[2] = new Person(\"Bob\", 28);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u4f7f\u7528\u4e2d\u62ec\u53f7\u8bbf\u95ee\u6570\u7ec4\u5143\u7d20<\/strong><\/p>\n<p>\u8981\u8bbf\u95ee\u6570\u7ec4\u4e2d\u7684\u7279\u5b9a\u5143\u7d20\uff0c\u53ef\u4ee5\u4f7f\u7528\u4e2d\u62ec\u53f7\u8fd0\u7b97\u7b26 []\u3002\u4f8b\u5982\uff0c\u8981\u8bbf\u95ee\u6570\u7ec4\u4e2d\u7b2c\u4e00\u4e2a\u5143\u7d20\uff0c\u53ef\u4ee5\u6267\u884c\u4ee5\u4e0b\u64cd\u4f5c\uff1a<\/p>\n<pre>Person person1 = people[0];<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>3. \u8c03\u7528\u7c7b\u65b9\u6cd5<\/strong><\/p>\n<p>\u73b0\u5728\u53ef\u4ee5\u8c03\u7528\u6570\u7ec4\u5143\u7d20\u7684\u7c7b\u65b9\u6cd5\u3002\u4f8b\u5982\uff0c\u8981\u8c03\u7528 Person \u7c7b\u7684 getAge() \u65b9\u6cd5\uff0c\u53ef\u4ee5\u6267\u884c\u4ee5\u4e0b\u64cd\u4f5c\uff1a<\/p>\n<pre>int age = person1.getAge();<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u793a\u4f8b\u4ee3\u7801\uff1a<\/strong><\/p>\n<pre>public class Main {\n\n    public static void main(String[] args) {\n        Person[] people = new Person[3];\n        people[0] = new Person(\"John\", 25);\n        people[1] = new Person(\"Mary\", 30);\n        people[2] = new Person(\"Bob\", 28);\n\n        for (Person person : people) {\n            System.out.println(\"Name: \" + person.getName());\n            System.out.println(\"Age: \" + person.getAge());\n        }\n    }\n}\n\nclass Person {\n    private String name;\n    private int age;\n\n    public Person(String name, int age) {\n        this.name = name;\n        this.age = age;\n    }\n\n    public String getName() {\n        return name;\n    }\n\n    public int getAge() {\n        return age;\n    }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u600e\u4e48\u8c03\u7528\u7c7b\u6570\u7ec4\u7684\u7c7b\u65b9\u6cd5\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\u8c03\u7528\u6570\u7ec4\u5143\u7d20\u7684\u7c7b\u65b9\u6cd5\uff0c\u9700\u8981\u6267\u884c\u4ee5\u4e0b\u6b65\u9aa4\uff1a\u5b9a\u4e49\u6570\u7ec4\u5e76\u521b\u5efa\u5b9e\u4f8b\uff1b\u4f7f\u7528\u4e2d\u62ec\u53f7 [] \u8bbf\u95ee\u6570\u7ec4\u5143\u7d20\uff1b\u8c03\u7528\u7c7b\u65b9\u6cd5\u3002 \u5982\u4f55\u4f7f\u7528 Java \u8c03\u7528\u6570\u7ec4\u5143\u7d20\u7684\u7c7b\u65b9\u6cd5 \u8981\u8c03\u7528\u6570\u7ec4\u5143\u7d20\u7684\u7c7b\u65b9\u6cd5\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u6b65\u9aa4\uff1a 1. \u5b9a\u4e49\u6570\u7ec4\u5e76\u521b\u5efa\u5b9e\u4f8b \u9996\u5148\uff0c\u9700\u8981\u5b9a\u4e49\u4e00\u4e2a\u6570\u7ec4\u53d8\u91cf\u5e76\u521b\u5efa\u6570\u7ec4\u5143\u7d20\u7684\u5b9e\u4f8b\u3002\u4f8b\u5982\uff0c\u8981\u521b\u5efa\u4e00\u4e2a\u5305\u542b Person \u7c7b\u5bf9\u8c61\u7684\u6570\u7ec4\uff0c\u53ef\u4ee5\u6267\u884c\u4ee5\u4e0b\u64cd\u4f5c\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b Person[] people = new Person[3]; people[0] = new Person(&#8220;John&#8221;, 25); people[1] = new Person(&#8220;Mary&#8221;, 30); people[2] = new Person(&#8220;Bob&#8221;, 28); \u767b\u5f55\u540e\u590d\u5236 2. \u4f7f\u7528\u4e2d\u62ec\u53f7\u8bbf\u95ee\u6570\u7ec4\u5143\u7d20 \u8981\u8bbf\u95ee\u6570\u7ec4\u4e2d\u7684\u7279\u5b9a\u5143\u7d20\uff0c\u53ef\u4ee5\u4f7f\u7528\u4e2d\u62ec\u53f7\u8fd0\u7b97\u7b26 []\u3002\u4f8b\u5982\uff0c\u8981\u8bbf\u95ee\u6570\u7ec4\u4e2d\u7b2c\u4e00\u4e2a\u5143\u7d20\uff0c\u53ef\u4ee5\u6267\u884c\u4ee5\u4e0b\u64cd\u4f5c\uff1a Person person1 = people[0]; \u767b\u5f55\u540e\u590d\u5236 3. \u8c03\u7528\u7c7b\u65b9\u6cd5 \u73b0\u5728\u53ef\u4ee5\u8c03\u7528\u6570\u7ec4\u5143\u7d20\u7684\u7c7b\u65b9\u6cd5\u3002\u4f8b\u5982\uff0c\u8981\u8c03\u7528 Person \u7c7b\u7684 getAge() \u65b9\u6cd5\uff0c\u53ef\u4ee5\u6267\u884c\u4ee5\u4e0b\u64cd\u4f5c\uff1a int age = person1.getAge(); \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-66656","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/66656","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=66656"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/66656\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=66656"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=66656"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=66656"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}