{"id":34498,"date":"2024-11-26T17:46:55","date_gmt":"2024-11-26T09:46:55","guid":{"rendered":"https:\/\/fwq.ai\/blog\/34498\/"},"modified":"2024-11-26T17:46:55","modified_gmt":"2024-11-26T09:46:55","slug":"java%e8%87%aa%e5%ae%9a%e4%b9%89%e7%b1%bb%e6%95%b0%e7%bb%84%e6%80%8e%e4%b9%88%e8%b5%8b%e5%80%bc","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/34498\/","title":{"rendered":"java\u81ea\u5b9a\u4e49\u7c7b\u6570\u7ec4\u600e\u4e48\u8d4b\u503c"},"content":{"rendered":"<blockquote><p>\n  \u56de\u7b54\uff1ajava \u4e2d\u81ea\u5b9a\u4e49\u7c7b\u6570\u7ec4\u7684\u8d4b\u503c\u6d89\u53ca\u4f7f\u7528\u6570\u7ec4\u5143\u7d20\u7d22\u5f15\u548c new \u5173\u952e\u5b57\u521b\u5efa\u65b0\u5bf9\u8c61\u3002\u8be6\u7ec6\u63cf\u8ff0\uff1a\u58f0\u660e\u4e00\u4e2a\u81ea\u5b9a\u4e49\u7c7b\u6570\u7ec4\uff08\u4f8b\u5982\uff0cstudent[] students = new student[2]\uff09\u3002\u4f7f\u7528 new \u5173\u952e\u5b57\u4e3a\u6570\u7ec4\u5143\u7d20\u521b\u5efa\u65b0\u7684\u81ea\u5b9a\u4e49\u7c7b\u5bf9\u8c61\uff08\u4f8b\u5982\uff0cstudents[0] = new student(&#8220;john&#8221;, 20)\uff09\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/02\/2024110215154777094.jpg\" class=\"aligncenter\" title=\"java\u81ea\u5b9a\u4e49\u7c7b\u6570\u7ec4\u600e\u4e48\u8d4b\u503c\u63d2\u56fe\" alt=\"java\u81ea\u5b9a\u4e49\u7c7b\u6570\u7ec4\u600e\u4e48\u8d4b\u503c\u63d2\u56fe\" \/><\/p>\n<p><strong>Java \u81ea\u5b9a\u4e49\u7c7b\u6570\u7ec4\u8d4b\u503c<\/strong><\/p>\n<p>\u5728 Java \u4e2d\uff0c\u81ea\u5b9a\u4e49\u7c7b\u6570\u7ec4\u662f\u6307\u5305\u542b\u81ea\u5b9a\u4e49\u7c7b\u5bf9\u8c61\u800c\u4e0d\u662f\u57fa\u672c\u6570\u636e\u7c7b\u578b\u7684\u6570\u7ec4\u3002\u8d4b\u503c\u662f\u5411\u6570\u7ec4\u5143\u7d20\u5206\u914d\u503c\u7684\u8bed\u6cd5\u64cd\u4f5c\u3002<\/p>\n<p><strong>\u8d4b\u503c<\/strong><\/p>\n<p>\u8981\u5411\u81ea\u5b9a\u4e49\u7c7b\u6570\u7ec4\u5143\u7d20\u8d4b\u503c\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>\/\/ \u6570\u7ec4\u53d8\u91cf\nCustomClass[] array;\n\n\/\/ \u5411\u6570\u7ec4\u5143\u7d20\u8d4b\u503c\narray[index] = new CustomClass();<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\uff1a<\/p>\n<ul>\n<li>array\uff1a\u8981\u8d4b\u503c\u7684\u6570\u7ec4\u53d8\u91cf<\/li>\n<li>index\uff1a\u8981\u8d4b\u503c\u7684\u6570\u7ec4\u5143\u7d20\u7d22\u5f15<\/li>\n<li>new CustomClass()\uff1a\u4e00\u4e2a\u7528\u4e8e\u521d\u59cb\u5316\u6570\u7ec4\u5143\u7d20\u7684\u65b0\u81ea\u5b9a\u4e49\u7c7b\u5bf9\u8c61<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b<\/strong><\/p>\n<p>\u4f8b\u5982\uff0c\u8003\u8651\u4e00\u4e2a\u540d\u4e3a Student \u7684\u81ea\u5b9a\u4e49\u7c7b\uff0c\u5176\u4e2d\u5305\u542b name \u548c age \u5b57\u6bb5\u3002\u8981\u5411 Student \u81ea\u5b9a\u4e49\u7c7b\u6570\u7ec4\u8d4b\u503c\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<pre>\/\/ \u521b\u5efa\u4e00\u4e2a\u81ea\u5b9a\u4e49\u7c7b\u6570\u7ec4\nStudent[] students = new Student[2];\n\n\/\/ \u5411\u6570\u7ec4\u5143\u7d20\u8d4b\u503c\nstudents[0] = new Student(\"John\", 20);\nstudents[1] = new Student(\"Mary\", 25);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0c\u6570\u7ec4 students \u5df2\u88ab\u521b\u5efa\u4e3a\u5305\u542b\u4e24\u4e2a Student \u5143\u7d20\u7684\u6570\u7ec4\u3002\u7136\u540e\uff0c\u4f7f\u7528 new \u5173\u952e\u5b57\u521b\u5efa\u4e24\u4e2a Student \u5bf9\u8c61\uff0c\u5e76\u5c06\u5b83\u4eec\u5206\u522b\u5206\u914d\u7ed9\u6570\u7ec4\u7684\u4e24\u4e2a\u5143\u7d20\u3002<\/p>\n<p><strong>\u6ce8\u610f<\/strong><\/p>\n<p>\u8bf7\u6ce8\u610f\uff0c\u5728 Java \u4e2d\uff0c\u6570\u7ec4\u5143\u7d20\u59cb\u7ec8\u4ece\u7d22\u5f15 0 \u5f00\u59cb\u3002\u56e0\u6b64\uff0c\u8981\u8bbf\u95ee\u7b2c\u4e00\u4e2a\u6570\u7ec4\u5143\u7d20\uff0c\u9700\u8981\u4f7f\u7528\u7d22\u5f15 0\uff0c\u800c\u8981\u8bbf\u95ee\u6700\u540e\u4e00\u4e2a\u5143\u7d20\uff0c\u9700\u8981\u4f7f\u7528\u7d22\u5f15 array.length &#8211; 1\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fjava\u81ea\u5b9a\u4e49\u7c7b\u6570\u7ec4\u600e\u4e48\u8d4b\u503c\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>\u56de\u7b54\uff1ajava \u4e2d\u81ea\u5b9a\u4e49\u7c7b\u6570\u7ec4\u7684\u8d4b\u503c\u6d89\u53ca\u4f7f\u7528\u6570\u7ec4\u5143\u7d20\u7d22\u5f15\u548c new \u5173\u952e\u5b57\u521b\u5efa\u65b0\u5bf9\u8c61\u3002\u8be6\u7ec6\u63cf\u8ff0\uff1a\u58f0\u660e\u4e00\u4e2a\u81ea\u5b9a\u4e49\u7c7b\u6570\u7ec4\uff08\u4f8b\u5982\uff0cstudent[] students = new student[2]\uff09\u3002\u4f7f\u7528 new \u5173\u952e\u5b57\u4e3a\u6570\u7ec4\u5143\u7d20\u521b\u5efa\u65b0\u7684\u81ea\u5b9a\u4e49\u7c7b\u5bf9\u8c61\uff08\u4f8b\u5982\uff0cstudents[0] = new student(&#8220;john&#8221;, 20)\uff09\u3002 Java \u81ea\u5b9a\u4e49\u7c7b\u6570\u7ec4\u8d4b\u503c \u5728 Java \u4e2d\uff0c\u81ea\u5b9a\u4e49\u7c7b\u6570\u7ec4\u662f\u6307\u5305\u542b\u81ea\u5b9a\u4e49\u7c7b\u5bf9\u8c61\u800c\u4e0d\u662f\u57fa\u672c\u6570\u636e\u7c7b\u578b\u7684\u6570\u7ec4\u3002\u8d4b\u503c\u662f\u5411\u6570\u7ec4\u5143\u7d20\u5206\u914d\u503c\u7684\u8bed\u6cd5\u64cd\u4f5c\u3002 \u8d4b\u503c \u8981\u5411\u81ea\u5b9a\u4e49\u7c7b\u6570\u7ec4\u5143\u7d20\u8d4b\u503c\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \/\/ \u6570\u7ec4\u53d8\u91cf CustomClass[] array; \/\/ \u5411\u6570\u7ec4\u5143\u7d20\u8d4b\u503c array[index] = new CustomClass(); \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d\uff1a array\uff1a\u8981\u8d4b\u503c\u7684\u6570\u7ec4\u53d8\u91cf index\uff1a\u8981\u8d4b\u503c\u7684\u6570\u7ec4\u5143\u7d20\u7d22\u5f15 new CustomClass()\uff1a\u4e00\u4e2a\u7528\u4e8e\u521d\u59cb\u5316\u6570\u7ec4\u5143\u7d20\u7684\u65b0\u81ea\u5b9a\u4e49\u7c7b\u5bf9\u8c61 \u793a\u4f8b \u4f8b\u5982\uff0c\u8003\u8651\u4e00\u4e2a\u540d\u4e3a Student \u7684\u81ea\u5b9a\u4e49\u7c7b\uff0c\u5176\u4e2d\u5305\u542b name \u548c age \u5b57\u6bb5\u3002\u8981\u5411 Student \u81ea\u5b9a\u4e49\u7c7b\u6570\u7ec4\u8d4b\u503c\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\uff1a \/\/ \u521b\u5efa\u4e00\u4e2a\u81ea\u5b9a\u4e49\u7c7b\u6570\u7ec4 Student[] students = new Student[2]; [&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-34498","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/34498","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=34498"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/34498\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=34498"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=34498"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=34498"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}