{"id":82,"date":"2015-03-30T11:34:35","date_gmt":"2015-03-30T03:34:35","guid":{"rendered":"https:\/\/ai.zhousir.top\/?p=82"},"modified":"2026-08-18T12:09:25","modified_gmt":"2026-08-18T04:09:25","slug":"java%e7%bb%a7%e6%89%bf%e4%b8%ad%e6%96%b9%e6%b3%95%e7%9a%84%e8%a6%86%e7%9b%96%e5%92%8c%e9%87%8d%e8%bd%bd","status":"publish","type":"post","link":"https:\/\/ai.zhousir.top\/?p=82","title":{"rendered":"Java\u7ee7\u627f\u4e2d\u65b9\u6cd5\u7684\u8986\u76d6\u548c\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;\">\u7ee7\u627f\u91cc\uff0c\u5b50\u7c7b\u53ef\u4ee5\u6539\u5199\u4ece\u7236\u7c7b\u62ff\u6765\u7684\u65b9\u6cd5\uff1a\u540d\u79f0\u3001\u8fd4\u56de\u503c\u7c7b\u578b\u3001\u53c2\u6570\u5217\u8868\u90fd\u76f8\u540c\uff0c\u529f\u80fd\u5374\u4e0d\u540c\u3002\u8fd9\u5c31\u53eb<strong style=\"color: #4870ac;\">\u8986\u76d6\uff08override\uff09<\/strong>\u3002\u53c2\u6570\u5217\u8868\uff08\u7c7b\u578b\u3001\u4e2a\u6570\u3001\u987a\u5e8f\uff09\u6709\u4e00\u9879\u4e0d\u540c\uff0c\u5c31\u4e0d\u518d\u662f\u8986\u76d6\uff0c\u800c\u53ef\u80fd\u6784\u6210<strong style=\"color: #4870ac;\">\u91cd\u8f7d\uff08overload\uff09<\/strong>\u3002<\/p>\n<p style=\"margin: 1em 0px;\">\u8986\u76d6\u4e0d\u4f1a\u628a\u7236\u7c7b\u65b9\u6cd5\u4ece\u5185\u5b58\u91cc\u5220\u6389\uff0c\u53ea\u662f\u5bf9\u5b50\u7c7b\u5b9e\u4f8b\u6682\u65f6\u9690\u85cf\u3002\u5b50\u7c7b\u91cc\u8981\u8c03\u7528\u88ab\u76d6\u4f4f\u7684\u7236\u7c7b\u7248\u672c\uff0c\u7528 <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;\">super<\/code>\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\u8986\u76d6\u793a\u4f8b<\/h2>\n<p style=\"margin: 1em 0px;\">\u6784\u9020\u65b9\u6cd5\u4e0d\u80fd\u7ee7\u627f\uff0c\u5b50\u7c7b\u901a\u8fc7 <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;\">super(name)<\/code> \u8c03\u7528\u7236\u7c7b\u6784\u9020\u3002Dog \u8986\u76d6\u4e86 Animal \u7684 <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;\">say()<\/code>\uff1a<\/p>\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    public static void main(String[] args) {\n        Dog myDog = new Dog(\"\u82b1\u82b1\");\n        myDog.say();  \/\/ \u5b50\u7c7b\u5b9e\u4f8b\u8d70\u5b50\u7c7b\u65b9\u6cd5\n\n        Animal myAnimal = new Animal(\"\u8d1d\u8d1d\");\n        myAnimal.say();  \/\/ \u7236\u7c7b\u5b9e\u4f8b\u8d70\u7236\u7c7b\u65b9\u6cd5\n    }\n}\nclass Animal {\n    String name;\n    public Animal(String name) {\n        this.name = name;\n    }\n    public void say() {\n        System.out.println(\"\u6211\u662f\u4e00\u53ea\u5c0f\u52a8\u7269\uff0c\u6211\u7684\u540d\u5b57\u53eb\" + name + \"\uff0c\u6211\u4f1a\u53d1\u51fa\u53eb\u58f0\");\n    }\n}\nclass Dog extends Animal {\n    public Dog(String name) {\n        super(name);\n    }\n    public void say() {\n        System.out.println(\"\u6211\u662f\u4e00\u53ea\u5c0f\u72d7\uff0c\u6211\u7684\u540d\u5b57\u53eb\" + name + \"\uff0c\u6211\u4f1a\u53d1\u51fa\u6c6a\u6c6a\u7684\u53eb\u58f0\");\n    }\n}\n\/\/ \u8fd0\u884c\u7ed3\u679c\uff1a\n\/\/ \u6211\u662f\u4e00\u53ea\u5c0f\u72d7\uff0c\u6211\u7684\u540d\u5b57\u53eb\u82b1\u82b1\uff0c\u6211\u4f1a\u53d1\u51fa\u6c6a\u6c6a\u7684\u53eb\u58f0\n\/\/ \u6211\u662f\u4e00\u53ea\u5c0f\u52a8\u7269\uff0c\u6211\u7684\u540d\u5b57\u53eb\u8d1d\u8d1d\uff0c\u6211\u4f1a\u53d1\u51fa\u53eb\u58f0<\/code><\/pre>\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\u8986\u76d6\u539f\u5219<\/h2>\n<ul style=\"padding-left: 1rem; margin-left: 1rem; font-size: 0.9rem; list-style-type: disc;\">\n<li>\n<section>\u65b9\u6cd5\u540d\u3001\u53c2\u6570\u5217\u8868\u5fc5\u987b\u4e0e\u7236\u7c7b\u76f8\u540c\u3002\u8fd4\u56de\u7c7b\u578b\u901a\u5e38\u4e5f\u76f8\u540c\uff1bJava 5 \u8d77\u5141\u8bb8<strong style=\"color: #4870ac;\">\u534f\u53d8\u8fd4\u56de<\/strong>\uff08\u5b50\u7c7b\u8fd4\u56de\u7c7b\u578b\u662f\u7236\u7c7b\u8fd4\u56de\u7c7b\u578b\u7684\u5b50\u7c7b\u578b\uff09\u3002<\/section>\n<\/li>\n<li>\n<section>\u8986\u76d6\u65b9\u6cd5\u7684\u8bbf\u95ee\u6743\u9650\u4e0d\u80fd\u6bd4\u539f\u65b9\u6cd5\u66f4\u7a84\u3002<\/section>\n<\/li>\n<li>\n<section>\u8986\u76d6\u65b9\u6cd5\u4e0d\u80fd\u629b\u51fa\u6bd4\u539f\u65b9\u6cd5\u66f4\u591a\uff08\u66f4\u5bbd\uff09\u7684\u53d7\u68c0\u5f02\u5e38\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;\">final<\/code> \u65b9\u6cd5\u4e0d\u80fd\u8986\u76d6\u3002<\/section>\n<\/li>\n<li>\n<section>\u7236\u7c7b\u65b9\u6cd5\u82e5\u662f <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;\">private<\/code>\uff0c\u5b50\u7c7b\u91cc\u540c\u540d\u65b9\u6cd5\u53ea\u662f\u65b0\u65b9\u6cd5\uff0c\u5e76\u4e0d\u6784\u6210\u8986\u76d6\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> \u4e0d\u80fd\u8986\u76d6\u3002\u4e00\u8fb9 static\u3001\u4e00\u8fb9\u5b9e\u4f8b\uff0c\u5373\u4f7f\u5176\u5b83\u6761\u4ef6\u90fd\u50cf\u8986\u76d6\uff0c\u4e5f\u4f1a\u7f16\u8bd1\u9519\u8bef\u3002\u4e24\u8fb9\u90fd\u662f static \u65f6\u6ee1\u8db3\u300c\u540c\u540d\u540c\u53c2\u300d\u4e5f\u53ea\u662f\u9690\u85cf\uff0c\u7f16\u8bd1\u671f\u6309\u5f15\u7528\u7c7b\u578b\u7ed1\u5b9a\u3002<\/section>\n<\/li>\n<\/ul>\n<p style=\"margin: 1em 0px;\">\u7236\u7c7b\u548c\u5b50\u7c7b\u91cc\u7684\u65b9\u6cd5\u8fd8\u4f1a\u4e00\u8d77\u53c2\u4e0e\u91cd\u8f7d\u3002\u4f8b\u5982\u7236\u7c7b\u6709 <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;\">func()<\/code>\uff0c\u5b50\u7c7b\u6709 <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;\">func(int i)<\/code>\uff0c\u8fd9\u662f\u91cd\u8f7d\uff0c\u4e0d\u662f\u8986\u76d6\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;\">\u4e09\u3001\u8986\u76d6 vs \u91cd\u8f7d<\/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;\">\u5bf9\u6bd4\u9879<\/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;\">\u8986\u76d6 override<\/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;\">\u91cd\u8f7d overload<\/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;\">\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\u4e00\u81f4<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u5fc5\u987b\u4e0d\u4e00\u81f4<\/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;\">\u76f8\u540c\u6216\u534f\u53d8<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u65e0\u8981\u6c42\uff08\u4f46\u4e0d\u80fd\u53ea\u9760\u5b83\u533a\u5206\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;\">\u53d1\u751f\u4f4d\u7f6e<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u5b50\u7c7b\u5bf9\u7236\u7c7b<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u540c\u4e00\u7c7b\u4e2d\u7684\u65b9\u6cd5\uff08\u542b\u7ee7\u627f\u6765\u7684\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;\">\u6743\u9650 \/ \u5f02\u5e38<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u6709\u9650\u5236<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u65e0\u8fd9\u4e9b\u9650\u5236<\/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;\">\u6b21\u6570<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u4e00\u4e2a\u7236\u65b9\u6cd5\u5728\u4e00\u4e2a\u5b50\u7c7b\u91cc\u8986\u76d6\u4e00\u6b21<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u53ef\u4ee5\u591a\u6b21\u91cd\u8f7d<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\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\u8986\u76d6\u662f\u5b50\u7c7b\u7528\u76f8\u540c\u7b7e\u540d\u6539\u5199\u7236\u7c7b\u65b9\u6cd5\uff1b\u91cd\u8f7d\u662f\u540c\u540d\u4e0d\u540c\u53c2\u3002\u4e00\u4e2a\u770b\u7ee7\u627f\uff0c\u4e00\u4e2a\u770b\u53c2\u6570\u5217\u8868\u3002<\/strong><\/p>\n<\/blockquote>\n<\/section>\n","protected":false},"excerpt":{"rendered":"<p>\u7ee7\u627f\u91cc\uff0c\u5b50\u7c7b\u53ef\u4ee5\u6539\u5199\u4ece\u7236\u7c7b\u62ff\u6765\u7684\u65b9\u6cd5\uff1a\u540d\u79f0\u3001\u8fd4\u56de\u503c\u7c7b\u578b\u3001\u53c2\u6570\u5217\u8868\u90fd\u76f8\u540c\uff0c\u529f\u80fd\u5374\u4e0d\u540c\u3002\u8fd9\u5c31\u53eb\u8986\u76d6\uff08overrid [&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,31],"_links":{"self":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/82"}],"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=82"}],"version-history":[{"count":2,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/82\/revisions"}],"predecessor-version":[{"id":375,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/82\/revisions\/375"}],"wp:attachment":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=82"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=82"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=82"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}