{"id":122,"date":"2015-04-01T16:43:15","date_gmt":"2015-04-01T08:43:15","guid":{"rendered":"https:\/\/ai.zhousir.top\/?p=122"},"modified":"2026-08-18T12:09:27","modified_gmt":"2026-08-18T04:09:27","slug":"java%e6%8a%bd%e8%b1%a1%e7%b1%bb%e7%9a%84%e6%a6%82%e5%bf%b5%e5%92%8c%e4%bd%bf%e7%94%a8","status":"publish","type":"post","link":"https:\/\/ai.zhousir.top\/?p=122","title":{"rendered":"Java\u62bd\u8c61\u7c7b\u7684\u6982\u5ff5\u548c\u4f7f\u7528"},"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;\">\u81ea\u4e0a\u800c\u4e0b\u7684\u7ee7\u627f\u5c42\u6b21\u91cc\uff0c\u8d8a\u9760\u4e0a\u7684\u7c7b\u8d8a\u901a\u7528\uff0c\u751a\u81f3\u66f4\u62bd\u8c61\u3002\u7956\u5148\u7c7b\u5f80\u5f80\u53ea\u5305\u542b\u6700\u57fa\u672c\u7684\u6210\u5458\uff0c\u4eba\u4eec\u53ea\u628a\u5b83\u5f53\u4f5c\u6d3e\u751f\u5176\u4ed6\u7c7b\u7684\u57fa\u7c7b\uff0c\u800c\u4e0d\u4f1a\u62ff\u5b83\u6765 new \u5bf9\u8c61\u3002\u65b9\u6cd5\u4e5f\u53ef\u4ee5\u53ea\u7ed9\u51fa\u5b9a\u4e49\u3001\u4e0d\u5199\u5b9e\u73b0\uff0c\u4ea4\u7ed9\u5b50\u7c7b\u6309\u5177\u4f53\u9700\u6c42\u53bb\u5b8c\u6210\u3002<\/p>\n<p style=\"margin: 1em 0px;\">\u8fd9\u79cd\u53ea\u6709\u5b9a\u4e49\u3001\u6ca1\u6709\u65b9\u6cd5\u4f53\uff08\u6ca1\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;\">{}<\/code>\uff09\u7684\u65b9\u6cd5\u53eb\u505a<strong style=\"color: #4870ac;\">\u62bd\u8c61\u65b9\u6cd5<\/strong>\u3002\u542b\u6709\u4e00\u4e2a\u6216\u591a\u4e2a\u62bd\u8c61\u65b9\u6cd5\u7684\u7c7b\u5fc5\u987b\u58f0\u660e\u4e3a<strong style=\"color: #4870ac;\">\u62bd\u8c61\u7c7b<\/strong>\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;\">abstract<\/code> \u4fee\u9970\u3002<\/p>\n<p><!--more--><\/p>\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;\">\u8bf4\u6cd5<\/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;\">\u5bf9\u4e0d\u5bf9<\/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;\">\u5305\u542b\u62bd\u8c61\u65b9\u6cd5\u7684\u7c7b\u4e00\u5b9a\u662f\u62bd\u8c61\u7c7b<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u5bf9\uff0c\u5426\u5219\u7f16\u8bd1\u5931\u8d25<\/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;\">\u62bd\u8c61\u7c7b\u4e00\u5b9a\u5305\u542b\u62bd\u8c61\u65b9\u6cd5<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u9519\uff0c\u53ef\u4ee5\u4e00\u4e2a\u62bd\u8c61\u65b9\u6cd5\u90fd\u6ca1\u6709\uff0c\u53ea\u4e3a\u4e86\u7981\u6b62 new<\/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;\">\u62bd\u8c61\u7c7b\u4e0d\u80fd\u6709\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;\">\u9519\uff0c\u53ef\u4ee5\u6709\u666e\u901a\u6784\u9020\uff0c\u4f9b\u5b50\u7c7b super()\uff1b\u4e0d\u80fd\u662f abstract \u6784\u9020<\/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;\">\u62bd\u8c61\u7c7b\u4e0d\u80fd\u88ab\u5b9e\u4f8b\u5316<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u5bf9\uff0c\u4f46\u53ef\u4ee5\u58f0\u660e\u62bd\u8c61\u7c7b\u578b\u7684\u53d8\u91cf\u6307\u5411\u5b50\u7c7b\u5b9e\u4f8b<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\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\u62bd\u8c61\u7c7b\u91cc\u53ef\u4ee5\u6709\u5177\u4f53\u6210\u5458<\/h2>\n<p style=\"margin: 1em 0px;\">\u62bd\u8c61\u7c7b\u9664\u4e86\u62bd\u8c61\u65b9\u6cd5\uff0c\u8fd8\u53ef\u4ee5\u5305\u542b\u5b9e\u4f8b\u53d8\u91cf\u548c\u5df2\u7ecf\u5b9e\u73b0\u597d\u7684\u65b9\u6cd5\u3002\u5373\u4f7f\u6ca1\u6709\u4efb\u4f55\u62bd\u8c61\u65b9\u6cd5\uff0c\u4e5f\u53ef\u4ee5\u58f0\u660e\u4e3a\u62bd\u8c61\u7c7b\uff0c\u4e13\u95e8\u9632\u6b62\u88ab\u5b9e\u4f8b\u5316\u3002\u62bd\u8c61\u65b9\u6cd5\u5fc5\u987b\u5728\u5177\u4f53\u5b50\u7c7b\u4e2d\u5b9e\u73b0\uff08\u5b50\u7c7b\u82e5\u4ecd\u4e0d\u5b9e\u73b0\uff0c\u81ea\u5df1\u4e5f\u5f97\u7ee7\u7eed\u62bd\u8c61\uff09\u3002<\/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;\">import static java.lang.System.*;\npublic class Demo {\n    public static void main(String[] args) {\n        Teacher t = new Teacher();\n        t.setName(\"\u738b\u660e\");\n        t.work();\n        Driver d = new Driver();\n        d.setName(\"\u5c0f\u9648\");\n        d.work();\n    }\n}\nabstract class People {\n    private String name;\n    public void setName(String name) {\n        this.name = name;\n    }\n    public String getName() {\n        return this.name;\n    }\n    public abstract void work();\n}\nclass Teacher extends People {\n    public void work() {\n        out.println(\"\u6211\u7684\u540d\u5b57\u53eb\" + this.getName() + \"\uff0c\u6211\u6b63\u5728\u8bb2\u8bfe\uff0c\u8bf7\u5927\u5bb6\u4e0d\u8981\u4e1c\u5f20\u897f\u671b...\");\n    }\n}\nclass Driver extends People {\n    public void work() {\n        out.println(\"\u6211\u7684\u540d\u5b57\u53eb\" + this.getName() + \"\uff0c\u6211\u6b63\u5728\u5f00\u8f66\uff0c\u4e0d\u80fd\u63a5\u542c\u7535\u8bdd...\");\n    }\n}<\/code><\/pre>\n<p style=\"margin: 1em 0px;\">\u8fd0\u884c\u7ed3\u679c\uff1a\u6211\u7684\u540d\u5b57\u53eb\u738b\u660e\uff0c\u6211\u6b63\u5728\u8bb2\u8bfe\u2026\u2026\uff1b\u6211\u7684\u540d\u5b57\u53eb\u5c0f\u9648\uff0c\u6211\u6b63\u5728\u5f00\u8f66\u2026\u2026\u3002name \u548c getter\/setter \u662f\u516c\u5171\u5b9e\u73b0\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;\">work()<\/code> \u7559\u7ed9\u5404\u804c\u4e1a\u81ea\u5df1\u586b\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\u600e\u4e48\u4f7f\u7528\u62bd\u8c61\u7c7b<\/h2>\n<p style=\"margin: 1em 0px;\">\u62bd\u8c61\u7c7b\u4e0d\u80fd\u76f4\u63a5 <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;\">new People()<\/code>\uff0c\u5fc5\u987b\u7528\u5b50\u7c7b\u53bb\u5b9e\u73b0\uff0c\u518d\u7528\u5b50\u7c7b\u5b9e\u4f8b\u3002\u4f46\u53ef\u4ee5\u58f0\u660e\u7c7b\u578b\u4e3a\u62bd\u8c61\u7c7b\u7684\u53d8\u91cf\uff0c\u8ba9\u5b83\u6307\u5411\u5177\u4f53\u5b50\u7c7b\uff0c\u4e5f\u5c31\u662f\u628a\u62bd\u8c61\u7c7b\u5f53\u5f62\u53c2\u3001\u5b9e\u73b0\u7c7b\u5f53\u5b9e\u53c2\u2014\u2014\u8fd9\u662f\u591a\u6001\u3002<\/p>\n<p style=\"margin: 1em 0px;\">\u4e0d\u80fd\u6709\u62bd\u8c61\u6784\u9020\u65b9\u6cd5\uff0c\u4e5f\u4e0d\u80fd\u6709\u62bd\u8c61\u9759\u6001\u65b9\u6cd5\u3002\u6784\u9020\u65b9\u6cd5\u53ef\u4ee5\u6709\uff0c\u53ea\u662f\u7528\u6765\u7ed9\u5b50\u7c7b\u521d\u59cb\u5316\u7236\u7c7b\u90a3\u90e8\u5206\u72b6\u6001\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\u4ec0\u4e48\u65f6\u5019\u7c7b\u5fc5\u987b\u662f\u62bd\u8c61\u7684<\/h2>\n<ul style=\"padding-left: 1rem; margin-left: 1rem; font-size: 0.9rem; list-style-type: disc;\">\n<li>\n<section>\u7c7b\u91cc\u6709\u4e00\u4e2a\u6216\u591a\u4e2a\u62bd\u8c61\u65b9\u6cd5\u3002<\/section>\n<\/li>\n<li>\n<section>\u5b83\u662f\u62bd\u8c61\u7c7b\u7684\u5b50\u7c7b\uff0c\u5374\u6ca1\u6709\u628a\u7236\u7c7b\u62bd\u8c61\u65b9\u6cd5\u5168\u90e8\u5b9e\u73b0\u5b8c\u3002<\/section>\n<\/li>\n<li>\n<section>\u5b83\u5b9e\u73b0\u4e86\u67d0\u4e2a\u63a5\u53e3\uff0c\u5374\u6ca1\u6709\u628a\u63a5\u53e3\u91cc\u7684\u62bd\u8c61\u65b9\u6cd5\u5168\u90e8\u5b9e\u73b0\u5b8c\u3002<\/section>\n<\/li>\n<\/ul>\n<p style=\"margin: 1em 0px;\">\u8fd9\u4e9b\u60c5\u51b5\u4e0b\u7c7b<strong style=\"color: #4870ac;\">\u5fc5\u987b<\/strong>\u662f\u62bd\u8c61\u7c7b\uff1b\u53cd\u8fc7\u6765\uff0c\u62bd\u8c61\u7c7b\u4e0d\u5fc5\u51fa\u73b0\u8fd9\u4e9b\u60c5\u51b5\u2014\u2014\u5b83\u53ef\u4ee5\u662f\u4e00\u4e2a\u65b9\u6cd5\u5168\u90fd\u5b9e\u73b0\u597d\u7684\u7c7b\uff0c\u53ea\u662f\u4e0d\u5141\u8bb8\u76f4\u63a5\u5b9e\u4f8b\u5316\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\uff1a\u62bd\u8c61\u65b9\u6cd5\u6ca1\u6709\u65b9\u6cd5\u4f53\uff0c\u6709\u5b83\u7684\u7c7b\u5fc5\u987b abstract\uff1b\u62bd\u8c61\u7c7b\u4e0d\u80fd new\uff0c\u4f46\u53ef\u4ee5\u5f53\u7c7b\u578b\u6307\u5411\u5b50\u7c7b\uff0c\u628a\u516c\u5171\u5b9e\u73b0\u7559\u5728\u7236\u7c7b\u3001\u5dee\u5f02\u7559\u7ed9\u5b50\u7c7b\u3002<\/strong><\/p>\n<\/blockquote>\n<\/section>\n","protected":false},"excerpt":{"rendered":"<p>\u81ea\u4e0a\u800c\u4e0b\u7684\u7ee7\u627f\u5c42\u6b21\u91cc\uff0c\u8d8a\u9760\u4e0a\u7684\u7c7b\u8d8a\u901a\u7528\uff0c\u751a\u81f3\u66f4\u62bd\u8c61\u3002\u7956\u5148\u7c7b\u5f80\u5f80\u53ea\u5305\u542b\u6700\u57fa\u672c\u7684\u6210\u5458\uff0c\u4eba\u4eec\u53ea\u628a\u5b83\u5f53\u4f5c\u6d3e\u751f\u5176\u4ed6\u7c7b\u7684\u57fa [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[17],"tags":[43,39],"_links":{"self":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/122"}],"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=122"}],"version-history":[{"count":2,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/122\/revisions"}],"predecessor-version":[{"id":328,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/122\/revisions\/328"}],"wp:attachment":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=122"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=122"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=122"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}