{"id":6118,"date":"2022-06-30T23:25:54","date_gmt":"2022-06-30T15:25:54","guid":{"rendered":"http:\/\/123.57.164.21\/?p=6118"},"modified":"2022-06-30T23:25:54","modified_gmt":"2022-06-30T15:25:54","slug":"%e5%a6%82%e4%bd%95%e5%bd%bb%e5%ba%95%e7%90%86%e8%a7%a3java%e6%8a%bd%e8%b1%a1%e7%b1%bb","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=6118","title":{"rendered":"\u5982\u4f55\u5f7b\u5e95\u7406\u89e3Java\u62bd\u8c61\u7c7b"},"content":{"rendered":"\n<p>\u5230\u5e95\u4ec0\u4e48\u662f\u62bd\u8c61\u7c7b\uff0c\u6709\u65f6\u660e\u660e\u4e00\u4e2a\u666e\u901a\u7c7b\u5c31\u53ef\u4ee5\u89e3\u51b3\u4e86\uff0c\u4e3a\u5565\u975e\u5f97\u6574\u4e2a\u62bd\u8c61\u7c7b?  \u6211\u66fe\u5e26\u7740\u8fd9\u6837\u7684\u7591\u60d1\uff0c\u67e5\u4e86\u5f88\u591a\u8d44\u6599\uff0c\u770b\u4e86\u5f88\u591a\u6e90\u7801\uff0c\u5199\u4e86\u5f88\u591a\u4ee3\u7801\uff0c\u4ee5\u4e0b\u662f\u81ea\u5bb6\u7684\u7406\u89e3<\/p>\n\n\n\n<p><strong>\u4e00\u3001\u5f7b\u5e95\u7406\u89e3Java\u62bd\u8c61\u7c7b<\/strong><\/p>\n\n\n\n<p>\u5f53\u6211\u4eec\u65e0\u6cd5\u7406\u89e3\u4e00\u4e2a\u4e8b\u7269\u7684\u65f6\u5019\uff0c\u6211\u5f97\u8ffd\u5bfb\u4ed6\u7684\u672c\u6e90\uff1a\u4e07\u7269\u7686\u5bf9\u8c61<\/p>\n\n\n\n<p>\u5728\u9762\u5411\u5bf9\u8c61\u7684\u6982\u5ff5\u4e2d\uff0c\u4e16\u95f4\u4e07\u7269\u901a\u8fc7\u7c7b\u6765\u63cf\u7ed8\u7684\uff0c\u4f46\u5982\u679c\u4e00\u4e2a\u7c7b\u4e2d\u6ca1\u6709\u5305\u542b\u8db3\u591f\u7684\u4fe1\u606f\u6765\u63cf\u7ed8\u4e00\u4e2a\u5177\u4f53\u7684\u4e8b\u7269\u5bf9\u8c61\uff0c\u8fd9\u6837\u7684\u7c7b\u5c31\u662f\u62bd\u8c61\u7c7b\u3002\uff08\u53c2\u8003 https:\/\/www.runoob.com\/java\/java-abstraction.html\uff09<\/p>\n\n\n\n<p>\u65e0\u8bba\u4f60\u5728\u5176\u4ed6\u6e20\u9053\u770b\u5230\u8fc7\u591a\u5c11\u5173\u4e8e\u62bd\u8c61\u7c7b\u7684\u89e3\u91ca\uff0c\u90fd\u6ca1\u6709\u8fd9\u6837\u89e3\u91ca\u5408\u4e4e\u6839\u672c\uff01<\/p>\n\n\n\n<p>\u4e3e\u4e2a\u4f8b\u5b50\uff1a<\/p>\n\n\n\n<p>\u8ba9\u4f60\u8bbe\u8ba1\u4e00\u4e2a\u7b80\u5355\u7684\u5b66\u751f\u9009\u8bfe\u7cfb\u7edf\u3002<\/p>\n\n\n\n<p>\u57fa\u672c\u9700\u6c42\uff1a\u5b66\u751f\u9009\u8bfe\uff0c\u8001\u5e08\u6388\u8bfe\uff0c\u6bcf\u4e2a\u8001\u5e08\u53ea\u80fd\u63a5\u53d7\u6709\u9650\u4e2a\u4e2a\u5b66\u751f\uff0c\u6bcf\u4e2a\u5b66\u751f\u53ea\u80fd\u9009\u4e00\u4e2a\u8001\u5e08\u3002<\/p>\n\n\n\n<p>\u6700\u7ec8\u4f1a\u62bd\u8c61\u51fa\u5176\u4e2d2\u4e2a\u9886\u57df\u5bf9\u8c61\uff1a\u5b66\u751f\u3001\u8001\u5e08\u3002\u5f53\u6211\u4eec\u7528\u7c7b\u53bb\u63cf\u8ff0\u5b66\u751f\u3001\u8001\u5e08\u65f6\uff0c\u4ed6\u4eec\u7684\u5171\u6027\u662f\u4eba\uff08Person\uff09\uff1a\u6709\u540d\u5b57\u3001\u5e74\u9f84\u3001\u804c\u4e1a\u7b49\u7279\u5f81\uff0c\u6709\u4e0a\u8bfe\uff08\u5b66\u4e60\u3001\u6388\u8bfe\u90fd\u5c5e\u4e8e\u4e0a\u8bfe\uff09\u7b49\u884c\u4e3a\u3002<\/p>\n\n\n\n<p>\u6211\u4eec\u60f3\u60f3\u5149\u6709\u8fd9\u4e9b\u7279\u6027\u3001\u884c\u4e3a\uff0c\u5c31\u80fd\u5b8c\u6574\u7684\u63cf\u8ff0\u51fa\u4e00\u4e2a\u53ef\u5728\u9009\u8bfe\u7cfb\u7edf\u64cd\u4f5c\u7684\u5bf9\u8c61\uff08\u5b66\u751f\u6216\u8001\u5e08\uff09\u5417\uff1f\u663e\u7136\u4e0d\u884c\uff01\u5b66\u751f\u8fd8\u9700\u8981\uff1a\u6240\u9009\u8bfe\u7a0b\u3001\u9009\u4e2d\u7684\u8001\u5e08\u7b49\u5176\u4ed6\u7279\u5f81\uff0c\u8001\u5e08\u8fd8\u9700\u8981\uff1a\u5b66\u751f\u9650\u6570\u3001\u540d\u4e0b\u5b66\u751f\u7b49\u5176\u4ed6\u7279\u5f81\uff0c\u52a0\u4e0a\u8fd9\u4e9b\u4e1c\u897f\uff0c\u624d\u80fd\u5b8c\u6574\u7684\u63cf\u8ff0\u4e00\u4e2a\u53ef\u4f9b\u64cd\u4f5c\u7684\u5bf9\u8c61\uff01<\/p>\n\n\n\n<p>\u5982\u4e0b\u4ee3\u7801\uff0cPerson\u7c7b\uff0c\u4f5c\u4e3a\u62bd\u8c61\u7c7b\uff0cgoToClass\u65b9\u6cd5\u662f\u5b50\u7c7b\u5fc5\u987b\u91cd\u5199\u7684\u65b9\u6cd5\uff0c\u8868\u660e\u5b50\u7c7b\u662f\u53bb\u5b66\u4e60\u7684\uff0c\u8fd8\u662f\u4e0a\u8bfe\u7684\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">public abstract class Person {\n    protected String name;\n    protected int age;\n    protected int profession;\n\n    public abstract void goToClass();\n}\n<\/pre>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">public class Student extends Person {\n    private int selLesson;\n    private int selTeacher;\n\n    @Override\n    public void goToClass() {\n        System.out.println(\"go to studying\");\n    }\n}<\/pre>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">public class Teacher extends Person {\n    private int studentNumLimit;\n    private List&lt;String> students;\n\n    @Override\n    public void goToClass() {\n        System.out.println(\"give lessons\");\n    }\n}<\/pre>\n\n\n\n<p><strong>\u4e8c\u3001\u4e3a\u4ec0\u4e48\u8981\u7528\u62bd\u8c61\u7c7b \u4ec0\u4e48\u60c5\u51b5\u4e0b\u7528\u62bd\u8c61\u7c7b<\/strong><\/p>\n\n\n\n<ul><li>1\u3001\u6839\u672c\u539f\u56e0\uff1a\u65e0\u6cd5\u5b8c\u6574\u63cf\u8ff0\u4e00\u4e2a\u4e8b\u7269\u7684\u7c7b<\/li><li>2\u3001\u62bd\u8c61\u7c7b\u6709\u4e00\u4e2a\u7279\u5f81\uff0c\u5176\u62bd\u8c61\u65b9\u6cd5\uff0c\u5fc5\u987b\u5728\u5b50\u7c7b\u91cd\u5199\uff08\u5b50\u7c7b\u975e\u62bd\u8c61\u7c7b\uff09\uff0c\u6240\u4ee5\uff0c\u5f53\u6211\u4eec\u7236\u7c7b\u7684\u65b9\u6cd5\uff0c\u5fc5\u987b\u8981\u5b50\u7c7b\u91cd\u5199\u5b9e\u73b0\u65f6\uff0c\u7528\u62bd\u8c61\u7c7b\u3002\u5982\u4e0a\u9762\u7684 goToClass() \u65b9\u6cd5\uff0c\u5b66\u751f\u3001\u8001\u5e08\u53bb\u8bfe\u5802\u7684\u76ee\u7684\u5b8c\u5168\u4e0d\u540c\uff0c\u5fc5\u987b\u81ea\u5df1\u5b9e\u73b0\u3002<\/li><li>3\u3001\u8ddf\u63a5\u53e3\u76f8\u6bd4\uff0c\u63a5\u53e3\u7684\u65b9\u6cd5\u5fc5\u987b\u7531\u5b9e\u73b0\u7c7b\u5168\u90e8\u5b9e\u73b0\uff0c\u63a5\u53e3\u65b9\u6cd5\u6bd4\u8f83\u591a\u65f6\uff0c\u5c31\u4f1a\u9ebb\u70e6\uff0c\u800c\u62bd\u8c61\u7c7b\u6ca1\u6709\u8fd9\u6837\u7684\u9650\u5236\u3002\u6bd4\u5982jdk \u91cc\u9762\u7684 AbstractList\uff0c\u662fArrayList \u7684\u7236\u7c7b\uff0c\u91cc\u9762\u5168\u662f\u65b9\u6cd5\uff0c\u4f60\u53ea\u9700\u8981\u91cd\u5199\u81ea\u5df1\u9700\u8981\u7684<\/li><li>4\u3001\u6613\u4e8e\u7406\u89e3\uff0c\u6709\u65f6\u5019\uff0c\u8fd9\u6837\u7684\u8bbe\u8ba1\uff0c\u8ba9\u4eba\u66f4\u5bb9\u6613\u7406\u89e3\u5b83\u7684\u5c42\u7ea7\u7b49\u3002\u4e2a\u4eba\u8ba4\u4e3a\u6240\u6709\u7684\u8bbe\u8ba1\u539f\u5219\u90fd\u662f\u6b7b\u7684\uff0c\u4e3a\u4e86\u63d0\u9ad8\u4ee3\u7801\u7684\u5b9e\u9645\u53ef\u64cd\u6027\uff0c\u727a\u7272\u90e8\u5206\u8bbe\u8ba1\u539f\u5219\u662f\u53ef\u4ee5\u7684<\/li><\/ul>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5230\u5e95\u4ec0\u4e48\u662f\u62bd\u8c61\u7c7b\uff0c\u6709\u65f6\u660e\u660e\u4e00\u4e2a\u666e\u901a\u7c7b\u5c31\u53ef\u4ee5\u89e3\u51b3\u4e86\uff0c\u4e3a\u5565\u975e\u5f97\u6574\u4e2a\u62bd\u8c61\u7c7b? \u6211\u66fe\u5e26\u7740\u8fd9\u6837\u7684\u7591\u60d1\uff0c\u67e5\u4e86\u5f88\u591a\u8d44\u6599\uff0c\u770b\u4e86 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/6118"}],"collection":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6118"}],"version-history":[{"count":3,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/6118\/revisions"}],"predecessor-version":[{"id":6121,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/6118\/revisions\/6121"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6118"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6118"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6118"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}