{"id":202896,"date":"2025-05-22T10:30:09","date_gmt":"2025-05-22T02:30:09","guid":{"rendered":"https:\/\/server.hk\/cnblog\/202896\/"},"modified":"2025-05-22T10:30:09","modified_gmt":"2025-05-22T02:30:09","slug":"java%e5%87%bd%e6%95%b0%e9%87%8d%e8%bd%bd%e5%9c%a8%e7%bb%a7%e6%89%bf%e4%b8%ad%e7%9a%84%e5%ba%94%e7%94%a8","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/202896\/","title":{"rendered":"Java\u51fd\u6570\u91cd\u8f7d\u5728\u7ee7\u627f\u4e2d\u7684\u5e94\u7528"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>Java\u51fd\u6570\u91cd\u8f7d\u5728\u7ee7\u627f\u4e2d\u7684\u5e94\u7528<\/h1>\n<p>\u4f60\u5728\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u76f8\u5173\u7684\u77e5\u8bc6\u5417\uff1f\u672c\u6587<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aJava\u51fd\u6570\u91cd\u8f7d\u5728\u7ee7\u627f\u4e2d\u7684\u5e94\u7528\u300b<\/span>\uff0c\u4e3b\u8981\u4ecb\u7ecd\u7684\u5185\u5bb9\u5c31\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\uff0c\u5982\u679c\u4f60\u60f3\u63d0\u5347\u81ea\u5df1\u7684\u5f00\u53d1\u80fd\u529b\uff0c\u5c31\u4e0d\u8981\u9519\u8fc7\u8fd9\u7bc7\u6587\u7ae0\uff0c\u5927\u5bb6\u8981\u77e5\u9053\u7f16\u7a0b\u7406\u8bba\u57fa\u7840\u548c\u5b9e\u6218\u64cd\u4f5c\u90fd\u662f\u4e0d\u53ef\u6216\u7f3a\u7684\u54e6\uff01<\/p>\n<p>Java\u4e2d\u51fd\u6570\u91cd\u8f7d\u5141\u8bb8\u7c7b\u4e2d\u5b58\u5728\u540c\u540d\u5f02\u53c2\u65b9\u6cd5\uff0c\u800c\u7ee7\u627f\u4e2d\u91cd\u8f7d\u7236\u7c7b\u7684\u65b9\u6cd5\u65e2\u4e0d\u4f1a\u8986\u76d6\u539f\u6709\u65b9\u6cd5\uff0c\u53c8\u4f1a\u63d0\u4f9b\u540c\u540d\u5f02\u53c2\u7684\u65b9\u6cd5\u3002\u4f8b\u5982\uff0c\u5b50\u7c7bCircle\u7ee7\u627f\u7236\u7c7bShape\u7684draw()\u65b9\u6cd5\uff0c\u53c8\u91cd\u8f7d\u4e86\u8be5\u65b9\u6cd5\uff0c\u63d0\u4f9b\u4e86\u4e00\u4e2a\u5e26\u534a\u5f84\u53c2\u6570\u7684draw()\u65b9\u6cd5\u3002\u8fd9\u6837\uff0cCircle\u7c7b\u65e2\u53ef\u4ee5\u7ed8\u5236\u65e0\u53c2\u5f62\u72b6\uff0c\u53c8\u53ef\u4ee5\u7ed8\u5236\u5e26\u53c2\u5706\u5f62\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241027\/1729991436671d930c557bb.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>Java \u51fd\u6570\u91cd\u8f7d\u5728\u7ee7\u627f\u4e2d\u7684\u5e94\u7528<\/strong><\/p>\n<p>Java \u4e2d\u7684\u51fd\u6570\u91cd\u8f7d\u662f\u6307\u4e00\u4e2a\u7c7b\u4e2d\u53ef\u4ee5\u5b58\u5728\u591a\u4e2a\u5177\u6709\u76f8\u540c\u540d\u79f0\u4f46\u53c2\u6570\u4e0d\u540c\u7684\u65b9\u6cd5\u3002\u5f53\u4e00\u4e2a\u5b50\u7c7b\u7ee7\u627f\u7236\u7c7b\u65f6\uff0c\u5b50\u7c7b\u53ef\u4ee5\u91cd\u5199\u7236\u7c7b\u7684\u65b9\u6cd5\uff0c\u4f46\u4e5f\u53ef\u4ee5\u91cd\u8f7d\u7236\u7c7b\u7684\u65b9\u6cd5\u3002\u91cd\u8f7d\u7236\u7c7b\u7684\u65b9\u6cd5\u4e0e\u91cd\u5199\u7236\u7c7b\u7684\u65b9\u6cd5\u4e0d\u540c\uff0c\u91cd\u8f7d\u7684\u65b9\u6cd5\u4e0d\u4f1a\u8986\u76d6\u7236\u7c7b\u7684\u65b9\u6cd5\uff0c\u800c\u662f\u63d0\u4f9b\u4e86\u4e00\u4e2a\u5177\u6709\u76f8\u540c\u540d\u79f0\u4f46\u4e0d\u540c\u53c2\u6570\u7684\u65b9\u6cd5\u3002<\/p>\n<p><strong>\u5b9e\u6218\u6848\u4f8b<\/strong><\/p>\n<p>\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u7236\u7c7b <code>Shape<\/code>\uff0c\u5b83\u6709\u4e00\u4e2a\u540d\u4e3a <code>draw()<\/code> \u7684\u65b9\u6cd5\u6765\u7ed8\u5236\u5f62\u72b6\u3002\u73b0\u5728\uff0c\u6211\u4eec\u521b\u5efa\u4e00\u4e2a\u5b50\u7c7b <code>Circle<\/code>\uff0c\u5b83\u7ee7\u627f\u81ea <code>Shape<\/code>\u3002<code>Circle<\/code> \u7c7b\u4e5f\u9700\u8981\u4e00\u4e2a <code>draw()<\/code> \u65b9\u6cd5\u6765\u7ed8\u5236\u5706\u3002\u4f46\u662f\uff0c<code>Circle<\/code> \u7684 <code>draw()<\/code> \u65b9\u6cd5\u9700\u8981\u4e00\u4e2a\u534a\u5f84\u53c2\u6570\uff0c\u800c <code>Shape<\/code> \u7684 <code>draw()<\/code> \u65b9\u6cd5\u5219\u4e0d\u9700\u8981\u53c2\u6570\u3002<\/p>\n<p><strong>\u4ee3\u7801\u793a\u4f8b<\/strong><\/p>\n<pre>\/\/ Shape \u7c7b\nclass Shape {\n    public void draw() {\n        System.out.println(\"Drawing a shape.\");\n    }\n}\n\n\/\/ Circle \u7c7b\nclass Circle extends Shape {\n    @Override\n    public void draw() {\n        super.draw();  \/\/ \u8c03\u7528\u7236\u7c7b\u7684 draw() \u65b9\u6cd5\n        System.out.println(\"Drawing a circle.\");\n    }\n\n    public void draw(double radius) {\n        System.out.println(\"Drawing a circle with radius: \" + radius);\n    }\n}<\/pre>\n<p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c<code>Circle<\/code> \u7c7b\u91cd\u8f7d\u4e86\u7236\u7c7b <code>Shape<\/code> \u7684 <code>draw()<\/code> \u65b9\u6cd5\u3002\u7b2c\u4e00\u4e2a <code>draw()<\/code> \u65b9\u6cd5\u4e0d\u5e26\u53c2\u6570\uff0c\u8c03\u7528\u7236\u7c7b\u7684 <code>draw()<\/code> \u65b9\u6cd5\u6765\u7ed8\u5236\u4e00\u4e2a\u5f62\u72b6\u3002\u7b2c\u4e8c\u4e2a <code>draw()<\/code> \u65b9\u6cd5\u63a5\u53d7\u4e00\u4e2a\u534a\u5f84\u53c2\u6570\uff0c\u4e13\u95e8\u7528\u4e8e\u7ed8\u5236\u5706\u3002<\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u5728 <code>Main<\/code> \u7c7b\u4e2d\u521b\u5efa <code>Circle<\/code> \u5bf9\u8c61\u5e76\u8c03\u7528\u8fd9\u4e24\u4e2a <code>draw()<\/code> \u65b9\u6cd5\uff1a<\/p>\n<pre>public class Main {\n    public static void main(String[] args) {\n        Circle circle = new Circle();\n        circle.draw();   \/\/ \u8c03\u7528\u4e0d\u5e26\u53c2\u6570\u7684 draw() \u65b9\u6cd5\n        circle.draw(5.0);  \/\/ \u8c03\u7528\u5e26\u6709\u534a\u5f84\u53c2\u6570\u7684 draw() \u65b9\u6cd5\n    }\n}<\/pre>\n<p>\u8f93\u51fa\u7ed3\u679c\uff1a<\/p>\n<pre>Drawing a shape.\nDrawing a circle with radius: 5.0<\/pre>\n<p>\u4eca\u5929\u5173\u4e8e\u300aJava\u51fd\u6570\u91cd\u8f7d\u5728\u7ee7\u627f\u4e2d\u7684\u5e94\u7528\u300b\u7684\u5185\u5bb9\u4ecb\u7ecd\u5c31\u5230\u6b64\u7ed3\u675f\uff0c\u5982\u679c\u6709\u4ec0\u4e48\u7591\u95ee\u6216\u8005\u5efa\u8bae\uff0c\u53ef\u4ee5\u5728\u516c\u4f17\u53f7\u4e0b\u591a\u591a\u56de\u590d\u4ea4\u6d41\uff1b\u6587\u4e2d\u82e5\u6709\u4e0d\u6b63\u4e4b\u5904\uff0c\u4e5f\u5e0c\u671b\u56de\u590d\u7559\u8a00\u4ee5\u544a\u77e5\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Java\u51fd\u6570\u91cd\u8f7d\u5728\u7ee7\u627f\u4e2d\u7684\u5e94\u7528 &#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-202896","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/202896","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=202896"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/202896\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=202896"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=202896"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=202896"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}