{"id":80,"date":"2015-03-30T11:30:37","date_gmt":"2015-03-30T03:30:37","guid":{"rendered":"https:\/\/ai.zhousir.top\/?p=80"},"modified":"2026-08-18T12:09:24","modified_gmt":"2026-08-18T04:09:24","slug":"java%e7%b1%bb%e4%b8%ad%e6%96%b9%e6%b3%95%e9%87%8d%e8%bd%bd","status":"publish","type":"post","link":"https:\/\/ai.zhousir.top\/?p=80","title":{"rendered":"Java\u7c7b\u4e2d\u65b9\u6cd5\u91cd\u8f7d"},"content":{"rendered":"<section id=\"wenyan\" style=\"font-family: system-ui, 'Apple Color Emoji', 'Segoe UI', 'Segoe UI Symbol', 'Noto Sans', Roboto, sans-serif; line-height: 1.75; font-size: 16px; color: #000000; caret-color: #000000;\" data-provider=\"WenYan\">\n<p style=\"margin: 1em 0px;\">\u540c\u4e00\u4e2a\u7c7b\u91cc\uff0c\u591a\u4e2a\u65b9\u6cd5\u53ef\u4ee5\u540c\u540d\uff0c\u53ea\u8981<strong style=\"color: #4870ac;\">\u53c2\u6570\u5217\u8868\u4e0d\u540c<\/strong>\uff0c\u8fd9\u53eb\u65b9\u6cd5\u91cd\u8f7d\uff08method overloading\uff09\u3002\u53c2\u6570\u5217\u8868\u4e5f\u53eb\u53c2\u6570\u7b7e\u540d\uff1a\u7c7b\u578b\u3001\u4e2a\u6570\u3001\u987a\u5e8f\uff0c\u6709\u4e00\u9879\u4e0d\u540c\u5c31\u7b97\u4e0d\u540c\u3002\u53ea\u6539\u53c2\u6570\u53d8\u91cf\u540d\u4e0d\u7b97\u3002<\/p>\n<p style=\"margin: 1em 0px;\">\u91cd\u8f7d\u662f\u9762\u5411\u5bf9\u8c61\u7684\u57fa\u672c\u80fd\u529b\uff1a\u540c\u4e00\u5957\u64cd\u4f5c\u540d\uff0c\u6309\u53c2\u6570\u9009\u51fa\u5408\u9002\u7684\u5b9e\u73b0\uff0c\u5c11\u9020\u4e00\u5806\u610f\u4e49\u76f8\u8fd1\u5374\u540d\u5b57\u4e0d\u540c\u7684\u65b9\u6cd5\u3002<\/p>\n<p><!--more--><\/p>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u4e00\u3001\u540c\u540d\u4e0d\u540c\u53c2<\/h2>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">public class Demo {\n    void test() {\n        System.out.println(\"No parameters\");\n    }\n    void test(int a) {\n        System.out.println(\"a: \" + a);\n    }\n    void test(int a, int b) {\n        System.out.println(\"a and b: \" + a + \" \" + b);\n    }\n    double test(double a) {\n        System.out.println(\"double a: \" + a);\n        return a * a;\n    }\n\n    public static void main(String args[]) {\n        Demo obj = new Demo();\n        obj.test();\n        obj.test(2);\n        obj.test(2, 3);\n        obj.test(2.0);\n    }\n}\n\/\/ \u8fd0\u884c\u7ed3\u679c\uff1a\n\/\/ No parameters\n\/\/ a: 2\n\/\/ a and b: 2 3\n\/\/ double a: 2.0<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u7f16\u8bd1\u5668\u6309\u8c03\u7528\u5904\u7684\u53c2\u6570\u4e2a\u6570\u3001\u7c7b\u578b\u53bb\u505a<strong style=\"color: #4870ac;\">\u91cd\u8f7d\u5206\u8fa8<\/strong>\uff1b\u5339\u914d\u4e0d\u4e0a\u5c31\u7f16\u8bd1\u62a5\u9519\u3002\u4e0a\u9762 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">test(2)<\/code> \u8d70 int \u7248\uff0c<code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">test(2.0)<\/code> \u8d70 double \u7248\u3002<\/p>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u4e8c\u3001\u91cd\u8f7d\u89c4\u5219<\/h2>\n<table style=\"display: table; text-align: left; overflow: auto; border-collapse: collapse; margin: 1.4em auto; max-width: 100%; table-layout: fixed; overflow-wrap: break-word; word-break: break-all;\" width=\"800\">\n<thead>\n<tr>\n<th style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top; text-align: center; font-weight: bold; color: #4870ac; background: #f7f7f7;\">\u9879\u76ee<\/th>\n<th style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top; text-align: center; font-weight: bold; color: #4870ac; background: #f7f7f7;\">\u8981\u6c42<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u65b9\u6cd5\u540d<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u5fc5\u987b\u76f8\u540c<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u53c2\u6570\u5217\u8868<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u5fc5\u987b\u4e0d\u540c\uff08\u4e2a\u6570\u3001\u7c7b\u578b\u6216\u987a\u5e8f\uff09<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u8fd4\u56de\u7c7b\u578b<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u53ef\u4ee5\u76f8\u540c\u4e5f\u53ef\u4ee5\u4e0d\u540c\uff1b<strong>\u4ec5\u8fd4\u56de\u7c7b\u578b\u4e0d\u540c\u4e0d\u80fd\u6784\u6210\u91cd\u8f7d<\/strong><\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u6784\u9020\u65b9\u6cd5<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u540c\u6837\u53ef\u4ee5\u91cd\u8f7d<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p style=\"margin: 1em 0px;\">\u539f\u6587\u6709\u4e24\u5904\u9700\u8981\u7ea0\u6b63\uff1a<\/p>\n<ul style=\"padding-left: 1rem; margin-left: 1rem; font-size: 0.9rem; list-style-type: disc;\">\n<li>\n<section><code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">final<\/code> \u65b9\u6cd5<strong style=\"color: #4870ac;\">\u4e0d\u80fd\u88ab\u8986\u76d6\uff08override\uff09<\/strong>\uff0c\u4f46<strong style=\"color: #4870ac;\">\u53ef\u4ee5\u91cd\u8f7d<\/strong>\u3002\u539f\u6587\u5199\u6210\u300cfinal \u4e0d\u80fd\u88ab\u91cd\u8f7d\u300d\u662f\u628a\u8986\u76d6\u548c\u91cd\u8f7d\u5f04\u6df7\u4e86\u3002<\/section>\n<\/li>\n<li>\n<section><code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">static<\/code> \u65b9\u6cd5\u540c\u6837<strong style=\"color: #4870ac;\">\u53ef\u4ee5\u91cd\u8f7d<\/strong>\u3002\u9759\u6001\u65b9\u6cd5\u4e0d\u80fd\u6309\u5b9e\u4f8b\u52a8\u6001\u8986\u76d6\uff0c\u5b50\u7c7b\u91cc\u540c\u540d\u540c\u53c2\u7684 static \u662f\u9690\u85cf\uff0c\u4e0d\u662f\u8986\u76d6\uff1b\u8fd9\u548c\u300c\u80fd\u4e0d\u80fd\u91cd\u8f7d\u300d\u4e0d\u662f\u4e00\u56de\u4e8b\u3002<\/section>\n<\/li>\n<\/ul>\n<blockquote style=\"display: block; font-size: 0.9em; border-left: 3px solid #4870ac; padding: 0.5em 1em; margin: 0px; background: #f6f8fa; color: #40464f;\">\n<p style=\"margin: 1em 0px;\"><strong style=\"color: #4870ac;\">\u4e00\u53e5\u8bdd\u603b\u7ed3\uff1a\u91cd\u8f7d\u770b\u65b9\u6cd5\u540d\u76f8\u540c\u3001\u53c2\u6570\u5217\u8868\u4e0d\u540c\uff1b\u7f16\u8bd1\u671f\u6309\u5b9e\u53c2\u9009\u578b\uff0c\u5355\u9760\u8fd4\u56de\u503c\u53d8\u4e0d\u4e86\u91cd\u8f7d\u3002<\/strong><\/p>\n<\/blockquote>\n<\/section>\n","protected":false},"excerpt":{"rendered":"<p>\u540c\u4e00\u4e2a\u7c7b\u91cc\uff0c\u591a\u4e2a\u65b9\u6cd5\u53ef\u4ee5\u540c\u540d\uff0c\u53ea\u8981\u53c2\u6570\u5217\u8868\u4e0d\u540c\uff0c\u8fd9\u53eb\u65b9\u6cd5\u91cd\u8f7d\uff08method overloading\uff09\u3002\u53c2\u6570\u5217\u8868 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[43,32],"_links":{"self":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/80"}],"collection":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=80"}],"version-history":[{"count":3,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/80\/revisions"}],"predecessor-version":[{"id":374,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/80\/revisions\/374"}],"wp:attachment":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=80"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=80"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=80"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}