{"id":78,"date":"2015-03-30T11:19:48","date_gmt":"2015-03-30T03:19:48","guid":{"rendered":"https:\/\/ai.zhousir.top\/?p=78"},"modified":"2026-08-18T12:09:24","modified_gmt":"2026-08-18T04:09:24","slug":"java%e7%bb%a7%e6%89%bf%e7%9a%84%e6%a6%82%e5%bf%b5%e4%b8%8e%e5%ae%9e%e7%8e%b0","status":"publish","type":"post","link":"https:\/\/ai.zhousir.top\/?p=78","title":{"rendered":"Java\u7ee7\u627f\u7684\u6982\u5ff5\u4e0e\u5b9e\u73b0"},"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\u662f\u7c7b\u4e0e\u7c7b\u4e4b\u95f4\u7684\u5173\u7cfb\uff0c\u548c\u73b0\u5b9e\u91cc\u300c\u513f\u5b50\u7ee7\u627f\u7236\u4eb2\u8d22\u4ea7\u300d\u7c7b\u4f3c\uff1a\u4e00\u4e2a\u7c7b\u4ece\u53e6\u4e00\u4e2a\u7c7b\u62ff\u5230\u65b9\u6cd5\u548c\u5c5e\u6027\u3002\u82e5 B \u7ee7\u627f A\uff0cB \u5c31\u62e5\u6709 A \u91cc\u53ef\u88ab\u7ee7\u627f\u7684\u6210\u5458\u3002<\/p>\n<p style=\"margin: 1em 0px;\">\u8bed\u6cd5\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;\">extends<\/code>\u3002Java \u7c7b\u662f<strong style=\"color: #4870ac;\">\u5355\u7ee7\u627f<\/strong>\uff1a\u4e00\u4e2a\u7c7b\u53ea\u80fd\u6709\u4e00\u4e2a\u76f4\u63a5\u7236\u7c7b\u3002\u591a\u4e2a\u7c7b\u578b\u53ef\u4ee5\u9760\u63a5\u53e3\u6765\u7ec4\u5408\uff0c\u63a5\u53e3\u4e4b\u95f4\u53ef\u4ee5\u591a\u7ee7\u627f\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\u4ece People \u5230 Teacher<\/h2>\n<p style=\"margin: 1em 0px;\">\u5df2\u7ecf\u6709\u4e00\u4e2a People \u7c7b\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;\">class People {\n    String name;\n    int age;\n    int height;\n\n    void say() {\n        System.out.println(\"\u6211\u7684\u540d\u5b57\u662f \" + name + \"\uff0c\u5e74\u9f84\u662f \" + age + \"\uff0c\u8eab\u9ad8\u662f \" + height);\n    }\n}<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u73b0\u5728\u8981\u5199 Teacher\uff1a\u540c\u6837\u6709 name\u3001age\u3001height \u548c <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>\uff0c\u8fd8\u8981\u52a0 school\u3001subject\u3001seniority \u548c <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;\">lecturing()<\/code>\u3002\u4e0d\u5fc5\u4ece\u5934\u518d\u5199\u4e00\u904d\uff0c\u5148\u7ee7\u627f People\uff0c\u518d\u8865\u81ea\u5df1\u7684\u6210\u5458\uff0c\u9700\u8981\u65f6\u8986\u76d6 <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;\">class Teacher extends People {\n    String school;   \/\/ \u6240\u5728\u5b66\u6821\n    String subject;  \/\/ \u5b66\u79d1\n    int seniority;   \/\/ \u6559\u9f84\n\n    void say() {\n        System.out.println(\"\u6211\u53eb\" + name + \"\uff0c\u5728\" + school + \"\u6559\" + subject + \"\uff0c\u6709\" + seniority + \"\u5e74\u6559\u9f84\");\n    }\n\n    void lecturing() {\n        System.out.println(\"\u6211\u5df2\u7ecf\" + age + \"\u5c81\u4e86\uff0c\u4f9d\u7136\u7ad9\u5728\u8bb2\u53f0\u4e0a\u8bb2\u8bfe\");\n    }\n}<\/code><\/pre>\n<ul style=\"padding-left: 1rem; margin-left: 1rem; font-size: 0.9rem; list-style-type: disc;\">\n<li>\n<section>name\u3001age \u6ca1\u5728 Teacher \u91cc\u58f0\u660e\uff0c\u5374\u80fd\u76f4\u63a5\u7528\uff0c\u56e0\u4e3a\u7236\u7c7b\u5df2\u7ecf\u6709\u4e86\u3002<\/section>\n<\/li>\n<li>\n<section>Teacher \u662f People \u7684\u5b50\u7c7b\uff0cPeople \u662f Teacher \u7684\u7236\u7c7b\u3002<\/section>\n<\/li>\n<li>\n<section>\u5b50\u7c7b\u53ef\u4ee5\u8986\u76d6\u7236\u7c7b\u65b9\u6cd5\uff0c\u4e5f\u53ef\u4ee5\u65b0\u589e\u81ea\u5df1\u7684\u65b9\u6cd5\u3002<\/section>\n<\/li>\n<li>\n<section>\u5b50\u7c7b\u7ee7\u627f\u7236\u7c7b\u4e2d <strong style=\"color: #4870ac;\">\u9664 private \u4ee5\u5916<\/strong>\u7684\u6210\u5458\uff08\u539f\u6587\u300c\u4ee5\u4e3a\u300d\u5e94\u4e3a\u300c\u4ee5\u5916\u300d\uff09\u3002<\/section>\n<\/li>\n<li>\n<section><strong style=\"color: #4870ac;\">\u6784\u9020\u65b9\u6cd5\u4e0d\u80fd\u88ab\u7ee7\u627f\u3002<\/strong><\/section>\n<\/li>\n<\/ul>\n<p style=\"margin: 1em 0px;\">\u7ef4\u62a4\u4e0a\u8fd9\u662f\u8fdb\u6b65\uff1a\u6539 People\uff0cTeacher \u81ea\u52a8\u5e26\u4e0a\u53d8\u66f4\uff0c\u7a0b\u5e8f\u5458\u4e3b\u8981\u8d1f\u8d23\u91cd\u65b0\u7f16\u8bd1\u3002\u5f53\u7136\uff0c\u8986\u76d6\u8fc7\u7684\u65b9\u6cd5\u4e0d\u4f1a\u8ddf\u7740\u7236\u7c7b\u5b9e\u73b0\u4e00\u8d77\u53d8\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\u5b8c\u6574\u793a\u4f8b<\/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    public static void main(String[] args) {\n        Teacher t = new Teacher();\n        t.name = \"\u5c0f\u5e03\";\n        t.age = 70;\n        t.school = \"\u6e05\u534e\u5927\u5b66\";\n        t.subject = \"Java\";\n        t.seniority = 12;\n        t.say();\n        t.lecturing();\n    }\n}\nclass People {\n    String name;\n    int age;\n    int height;\n\n    void say() {\n        System.out.println(\"\u6211\u7684\u540d\u5b57\u662f \" + name + \"\uff0c\u5e74\u9f84\u662f \" + age + \"\uff0c\u8eab\u9ad8\u662f \" + height);\n    }\n}\nclass Teacher extends People {\n    String school;\n    String subject;\n    int seniority;\n\n    void say() {\n        System.out.println(\"\u6211\u53eb\" + name + \"\uff0c\u5728\" + school + \"\u6559\" + subject + \"\uff0c\u6709\" + seniority + \"\u5e74\u6559\u9f84\");\n    }\n\n    void lecturing() {\n        System.out.println(\"\u6211\u5df2\u7ecf\" + age + \"\u5c81\u4e86\uff0c\u4f9d\u7136\u7ad9\u5728\u8bb2\u53f0\u4e0a\u8bb2\u8bfe\");\n    }\n}\n\/\/ \u8fd0\u884c\u7ed3\u679c\uff1a\n\/\/ \u6211\u53eb\u5c0f\u5e03\uff0c\u5728\u6e05\u534e\u5927\u5b66\u6559Java\uff0c\u670912\u5e74\u6559\u9f84\n\/\/ \u6211\u5df2\u7ecf70\u5c81\u4e86\uff0c\u4f9d\u7136\u7ad9\u5728\u8bb2\u53f0\u4e0a\u8bb2\u8bfe<\/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;\">\u4e09\u3001\u5355\u7ee7\u627f\u4e0e\u6784\u9020\u65b9\u6cd5<\/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;\">\u89c4\u5219<\/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;\">\u8bf4\u660e<\/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;\">\u5355\u7ee7\u627f<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u4e00\u4e2a\u7c7b\u53ea\u80fd extends \u4e00\u4e2a\u7236\u7c7b<\/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;\">\u63a5\u53e3<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u7c7b\u53ef\u5b9e\u73b0\u591a\u4e2a\u63a5\u53e3\uff1b\u63a5\u53e3\u53ef\u7ee7\u627f\u591a\u4e2a\u63a5\u53e3<\/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;\">\u4e0d\u80fd\u7ee7\u627f\u3002\u8981\u4e48\u81ea\u5df1\u5199\uff0c\u8981\u4e48\u4e00\u4e2a\u90fd\u4e0d\u5199\uff0c\u7531\u7f16\u8bd1\u5668\u7ed9\u9ed8\u8ba4\u65e0\u53c2\u6784\u9020<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p style=\"margin: 1em 0px;\">\u638c\u63e1\u300c\u6784\u9020\u65b9\u6cd5\u4e0d\u80fd\u7ee7\u627f\u300d\u5f88\u91cd\u8981\uff1a\u5b50\u7c7b\u6784\u9020\u91cc\u82e5\u8981\u521d\u59cb\u5316\u7236\u7c7b\u72b6\u6001\uff0c\u5e94\u5199 <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>\uff0c\u800c\u4e0d\u662f\u6307\u671b\u628a\u7236\u7c7b\u6784\u9020\u300c\u6284\u300d\u8fc7\u6765\u3002<\/p>\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\uff1aextends \u62ff\u8d70\u7236\u7c7b\u975e private \u6210\u5458\uff0c\u53ef\u4ee5\u8986\u76d6\u548c\u6269\u5c55\uff1b\u7c7b\u53ea\u80fd\u5355\u7ee7\u627f\uff0c\u6784\u9020\u65b9\u6cd5\u5fc5\u987b\u81ea\u5df1\u5199\u6216\u7528\u9ed8\u8ba4\u6784\u9020\u3002<\/strong><\/p>\n<\/blockquote>\n<\/section>\n","protected":false},"excerpt":{"rendered":"<p>\u7ee7\u627f\u662f\u7c7b\u4e0e\u7c7b\u4e4b\u95f4\u7684\u5173\u7cfb\uff0c\u548c\u73b0\u5b9e\u91cc\u300c\u513f\u5b50\u7ee7\u627f\u7236\u4eb2\u8d22\u4ea7\u300d\u7c7b\u4f3c\uff1a\u4e00\u4e2a\u7c7b\u4ece\u53e6\u4e00\u4e2a\u7c7b\u62ff\u5230\u65b9\u6cd5\u548c\u5c5e\u6027\u3002\u82e5 B \u7ee7\u627f A\uff0cB [&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,31],"_links":{"self":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/78"}],"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=78"}],"version-history":[{"count":2,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/78\/revisions"}],"predecessor-version":[{"id":373,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/78\/revisions\/373"}],"wp:attachment":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=78"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=78"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=78"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}