{"id":10006554,"date":"2022-09-20T22:22:19","date_gmt":"2022-09-20T14:22:19","guid":{"rendered":"https:\/\/ityet.com\/?p=10006554"},"modified":"2022-09-20T22:22:19","modified_gmt":"2022-09-20T14:22:19","slug":"%e4%bb%8e%e5%89%8d%e7%ab%af%e5%88%b0%e5%85%a8%e6%a0%88-%e6%9c%80%e5%85%a8%e9%9d%a2%e5%90%91%e5%af%b9%e8%b1%a1%e6%80%bb%e7%bb%93","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10006554","title":{"rendered":"\u4ece\u524d\u7aef\u5230\u5168\u6808 &#8212; \u6700\u5168\u9762\u5411\u5bf9\u8c61\u603b\u7ed3"},"content":{"rendered":"<blockquote><p>\u672c\u6587\u53c2\u4e0e\u4e86<a href=\"https:\/\/segmentfault.com\/a\/1190000042453662\">\u601d\u5426\u6280\u672f\u5f81\u6587<\/a>\uff0c\u6b22\u8fce\u6b63\u5728\u9605\u8bfb\u7684\u4f60\u4e5f\u52a0\u5165\u3002<\/p><\/blockquote>\n<p>\u4ece\u4e8b\u524d\u7aef\u7684\u8fd9\u4e24\u5e74\u4e2d\uff0c\u4e5f\u63a5\u89e6\u4e86\u540e\u7aef\u9886\u57df\uff0c\u50cf <code>PHP<\/code> <code>Node<\/code>, \u5e76\u4e14\u90fd\u7528\u5b83\u4eec\u505a\u8fc7\u4e00\u4e9b <code>demo<\/code> \u548c <code>\u79c1\u6d3b<\/code> ,<br \/>\u7ad9\u5728\u804c\u4e1a\u53d1\u5c55\u9053\u8def\u4e0a\u6765\u8bb2\uff0c\u4e86\u89e3\u540e\u7aef\u662f\u597d\u7684\uff0c\u81ea\u5df1\u53ef\u4ee5\u719f\u7ec3\u524d\u540e\u7684\u5f00\u53d1\u6d41\u7a0b\uff0c\u6574\u6761\u94fe\u8def\u4e0b\u6765\uff0c\u5f88\u6e05\u6670\uff0c\u61c2\u4e86\u540e\u7aef\uff0c\u5728\u81ea\u5df1\u4ee5\u540e\u521b\u4e1a\u6216\u8005\u63a5\u79c1\u6d3b\uff0c\u90fd\u662f\u4e0d\u9519\u7684\u3002 \u800c\u4e14\u73b0\u5728\u5728<code>Web<\/code>\u540e\u53f0\u9886\u57df, <code>Java<\/code> \u662f \u8001\u5927\u54e5\u4e86\uff0c<code>Spring<\/code> \u5168\u5bb6\u6876\u8d70\u904d\u5929\u4e0b\uff0c\u4e8e\u662f\u6700\u8fd1\u53c8\u91cd\u62fe <code>Java<\/code> \u4e86\uff0c<strong>\u4ece\u524d\u7aef\u8fc8\u5411\u5168\u6808<\/strong><\/p>\n<p>\u8fd9\u662f\u6211\u6700\u8fd1\u82b1\u4e86\u4e00\u5468\u7684\u65f6\u95f4\u590d\u76d8\u7684 <code>Java \u9762\u5411\u5bf9\u8c61<\/code> \u603b\u7ed3\uff0c\u5e0c\u671b\u80fd\u5e2e\u52a9\u5230\u4f60.<\/p>\n<h2>\u5bfc\u8bfb\u76ee\u5f55<\/h2>\n<p><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042517738\" alt=\"\u91cd\u5b66Java \u9762\u5411\u5bf9\u8c611.png\" title=\"\u91cd\u5b66Java \u9762\u5411\u5bf9\u8c611.png\" loading=\"lazy\"><\/p>\n<h2>\u5b66\u4e60\u8def\u7ebf<\/h2>\n<p>\u8fd9\u4efd\u5b66\u4e60\u8def\u7ebf \u662f \u6211\u8ddf\u7740 \u67d0up\u4e3b \u89c6\u9891\u603b\u7ed3\u7684\uff0c\u5f88\u5168\u9762<br \/><img decoding=\"async\" referrerpolicy=\"no-referrer\" src=\"https:\/\/segmentfault.com\/img\/remote\/1460000042517739\" alt=\"Java \u540e\u7aef\u5f00\u53d1\u5b66\u4e60\u8def\u7ebf.png\" title=\"Java \u540e\u7aef\u5f00\u53d1\u5b66\u4e60\u8def\u7ebf.png\" loading=\"lazy\"><\/p>\n<h2>\u91cd\u5b66Java<\/h2>\n<h3>\u4e00\u3001\u9762\u5411\u5bf9\u8c61 <code>OOP<\/code><\/h3>\n<h3>1. 1 \u5173\u4e8e <code>super<\/code> \u548c <code>this<\/code>  \u533a\u522b<\/h3>\n<h4><code>super<\/code><\/h4>\n<ol>\n<li><code>super<\/code> \u8c03\u7528\u7236\u7c7b\u7684\u6784\u9020\u65b9\u6cd5\uff0c\u5fc5\u987b\u5728\u5b50\u7c7b\u6784\u9020\u65b9\u6cd5\u4e2d\u7b2c\u4e00\u4e2a<\/li>\n<li><code>super<\/code> \u5fc5\u987b\u53ea\u80fd\u51fa\u73b0\u5728\u5b50\u7c7b\u7684\u65b9\u6cd5 \u6216\u8005 \u6784\u9020\u65b9\u6cd5 \u4e2d<\/li>\n<li><code>super<\/code>  \u548c <code> this<\/code>  \u4e0d\u80fd\u540c\u65f6\u51fa\u73b0\u5728\u8c03\u7528\u6784\u9020\u65b9\u6cd5<\/li>\n<\/ol>\n<h4><code>this<\/code><\/h4>\n<p>\u4ee3\u8868\u7684\u5bf9\u8c61\u4e0d\u540c:<\/p>\n<ol>\n<li><code>this<\/code> : \u672c\u8eab\u8c03\u7528\u8005\u8fd9\u4e2a\u5bf9\u8c61<\/li>\n<li><code>super<\/code> : \u4ee3\u8868\u7236\u7c7b\u5bf9\u8c61\u5e94\u7528<\/li>\n<\/ol>\n<h3>1.2 \u591a\u6001<\/h3>\n<p>\u540c\u4e00\u65b9\u6cd5\u53ef\u4ee5\u6839\u636e\u53d1\u9001\u5bf9\u8c61\u7684\u4e0d\u540c\u800c\u91c7\u7528\u591a\u79cd\u4e0d\u540c\u7684\u884c\u4e3a\u65b9\u5f0f\u3002<\/p>\n<p>\u4e00\u4e2a\u5bf9\u8c61\u7684\u5b9e\u9645\u7c7b\u578b\u662f\u786e\u5b9a\u7684\uff0c\u4f46\u53ef\u4ee5\u6307\u5411\u5bf9\u8c61\u7684\u5f15\u7528\u7c7b\u578b\u6709\u5f88\u591a\u3002<\/p>\n<p><strong>\u591a\u6001\u5b58\u5728\u6761\u4ef6<\/strong><\/p>\n<ol>\n<li>\u6709\u7ee7\u627f\u5173\u7cfb<\/li>\n<li>\u5b50\u7c7b\u91cd\u5199\u7236\u7c7b\u7684\u65b9\u6cd5<\/li>\n<li>\u7236\u7c7b\u5f15\u7528\u6307\u5411\u4e86\u5b50\u7c7b\u5bf9\u8c61<\/li>\n<\/ol>\n<p><strong>\u6ce8\u610f<\/strong><\/p>\n<ol>\n<li>\u5b50\u7c7b\u5982\u679c\u91cd\u5199\u4e86\u7236\u7c7b\u65b9\u6cd5\uff0c\u7236\u7c7b\u5bf9\u8c61\u662f\u8c03\u7528\u7684\u5b50\u7c7b\u91cd\u5199\u540e\u7684\u65b9\u6cd5<\/li>\n<\/ol>\n<h4>\u7c7b\u578b\u8f6c\u6362<\/h4>\n<p>\u7c7b\u578b\u8f6c\u6362\u76ee\u7684\uff1a <strong>\u65b9\u4fbf\u65b9\u6cd5\u8c03\u7528\uff0c\u964d\u7ea7\uff0c\u5347\u7ea7\uff0c\u51cf\u5c11\u4ee3\u7801\u91cd\u590d\u6027\uff0c\u4f46\u4e5f\u6709\u7f3a\u70b9\uff0c\u4e22\u5931\u7cbe\u5ea6\u6027<\/strong><\/p>\n<ol>\n<li>\u5411\u4e0a\u8f6c\u578b (\u5b50 \u8f6c \u7236 )  \u4f4e\u8f6c\u9ad8 \u53ef\u76f4\u63a5\u8f6c<\/li>\n<li>\n<p>\u5411\u4e0b\u8f6c\u578b \uff08\u7236 \u8f6c \u5b50\uff09 \u9ad8\u8f6c\u4f4e \u9700\u8981\u5f3a\u5236\u8f6c\u6362<\/p>\n<blockquote>\n<p>\u9ad8 \u8f6c \u4f4e \u540e\uff0c \u7136\u540e\u518d\u8fdb\u884c\u5f3a\u5236\u8f6c\u6362\uff0c   <\/p>\n<p><code>\u5b50\u7c7b\u578b  \u5b50\u5bf9\u8c61  =  (\u5b50\u7c7b\u578b) \u7236\u5bf9\u8c61<\/code><\/p>\n<\/blockquote>\n<\/li>\n<\/ol>\n<pre><code class=\"java\">    Person per = new Student()\n    Student student = (Student) per   \/\/  ((Student) per).\u65b9\u6cd5\/\u5c5e\u6027\n    \n    per.\u5b50\u5c5e\u6027\u548c\u65b9\u6cd5<\/code><\/pre>\n<h3>1.3  <code>static<\/code><\/h3>\n<h4>1.3.1  <code>static<\/code> \u7528\u9014<\/h4>\n<p>\u5728\u6ca1\u6709\u521b\u5efa\u5bf9\u8c61\u7684\u60c5\u51b5\u4e0b\u8c03\u7528\u65b9\u6cd5\u548c\u5c5e\u6027(\u9759\u6001\u7684)\u3002<\/p>\n<p><code>static<\/code> \u53ef\u4ee5\u7528\u6765\u4fee\u9970\u7c7b\u7684\u6210\u5458\u65b9\u6cd5\u3001\u7c7b\u7684\u6210\u5458\u53d8\u91cf\uff0c\u53e6\u5916\u53ef\u4ee5\u7f16\u5199static\u4ee3\u7801\u5757\u6765\u4f18\u5316\u7a0b\u5e8f\u6027\u80fd\u3002<\/p>\n<h4>1.3.2 <code>static<\/code>  \u9759\u6001\u65b9\u6cd5<\/h4>\n<ol>\n<li><code>static<\/code> \u65b9\u6cd5\u4e00\u822c\u79f0\u4f5c\u9759\u6001\u65b9\u6cd5,\u9759\u6001\u65b9\u6cd5\u4e0d\u4f9d\u8d56\u4e8e\u4efb\u4f55\u5bf9\u8c61\u5c31\u53ef\u4ee5\u8fdb\u884c\u8bbf\u95ee, \u56e0\u6b64\u5bf9\u4e8e\u9759\u6001\u65b9\u6cd5\u6765\u8bf4\uff0c\u662f\u6ca1\u6709this\u7684\u3002<\/li>\n<li>\u5728\u9759\u6001\u65b9\u6cd5\u4e2d<strong>\u4e0d\u80fd\u8bbf\u95ee\u7c7b\u7684\u975e\u9759\u6001\u6210\u5458\u53d8\u91cf\u548c\u975e\u9759\u6001\u6210\u5458\u65b9\u6cd5<\/strong>\uff0c\u56e0\u4e3a\u975e\u9759\u6001\u6210\u5458\u65b9\u6cd5\/\u53d8\u91cf\u90fd\u662f\u5fc5\u987b\u4f9d\u8d56\u5177\u4f53\u7684\u5bf9\u8c61\u624d\u80fd\u591f\u88ab\u8c03\u7528\u3002<\/li>\n<li>\u5728\u975e\u9759\u6001\u65b9\u6cd5\u4e2d\u662f\u53ef\u4ee5\u8bbf\u95ee\u9759\u6001\u6210\u5458\u65b9\u6cd5\/\u53d8\u91cf\u7684\u3002<\/li>\n<\/ol>\n<h4>1.3.3 <code>static<\/code> \u9759\u6001\u53d8\u91cf<\/h4>\n<p><strong>\u9759\u6001\u53d8\u91cf\u548c\u975e\u9759\u6001\u53d8\u91cf\u7684\u533a\u522b\u662f<\/strong><\/p>\n<ol>\n<li>\u9759\u6001\u53d8\u91cf\u88ab\u6240\u6709\u7684\u5bf9\u8c61\u6240\u5171\u4eab\uff0c\u5728\u5185\u5b58\u4e2d\u53ea\u6709\u4e00\u4e2a\u526f\u672c\uff0c\u5b83\u5f53\u4e14\u4ec5\u5f53\u5728\u7c7b\u521d\u6b21\u52a0\u8f7d\u65f6\u4f1a\u88ab\u521d\u59cb\u5316\u3002<\/li>\n<li>\u975e\u9759\u6001\u53d8\u91cf\u662f\u5bf9\u8c61\u6240\u62e5\u6709\u7684\uff0c\u5728\u521b\u5efa\u5bf9\u8c61\u7684\u65f6\u5019\u88ab\u521d\u59cb\u5316\uff0c\u5b58\u5728\u591a\u4e2a\u526f\u672c\uff0c\u5404\u4e2a\u5bf9\u8c61\u62e5\u6709\u7684\u526f\u672c\u4e92\u4e0d\u5f71\u54cd\u3002<\/li>\n<\/ol>\n<p>static\u6210\u5458\u53d8\u91cf\u7684\u521d\u59cb\u5316\u987a\u5e8f\u6309\u7167\u5b9a\u4e49\u7684\u987a\u5e8f\u8fdb\u884c\u521d\u59cb\u5316\u3002<\/p>\n<h4>1.3.4 <code>static<\/code> \u4ee3\u7801\u5757<\/h4>\n<p><code>static<\/code>\u5173\u952e\u5b57\u6765\u5f62\u6210\u9759\u6001\u4ee3\u7801\u5757\u4ee5\u4f18\u5316\u7a0b\u5e8f\u6027\u80fd,\u3002<\/p>\n<p><code>static<\/code>\u5757\u53ef\u4ee5\u7f6e\u4e8e\u7c7b\u4e2d\u7684\u4efb\u4f55\u5730\u65b9\uff0c\u7c7b\u4e2d\u53ef\u4ee5\u6709\u591a\u4e2a<code>static<\/code>\u5757\u3002\u5728\u7c7b\u521d\u6b21\u88ab\u52a0\u8f7d\u7684\u65f6\u5019\uff0c\u4f1a\u6309\u7167<code>static<\/code>\u5757\u7684\u987a\u5e8f\u6765\u6267\u884c\u6bcf\u4e2a<code>static<\/code>\u5757\uff0c\u5e76\u4e14\u53ea\u4f1a\u6267\u884c\u4e00\u6b21\u3002<\/p>\n<p><strong>\u53ef\u4ee5\u628a\u65b9\u6cd5\u4e2d\u5e38\u91cf\u653e\u5165\u5230 \u9759\u6001\u5757\u4e2d\uff0c\u8fd9\u6837\u4e0d\u81f3\u4e8e\uff0c\u6bcf\u6b21\u8c03\u7528\uff0c\u53c8\u91cd\u65b0\u521b\u5efa\uff0c\u9020\u6210\u7a7a\u95f4\u6d6a\u8d39\u3002<\/strong><\/p>\n<pre><code class=\"java\">public class Test {\n    private  static Date date ;\n    private  static SimpleDateFormat formatter;\n    static {\n         formatter= new SimpleDateFormat(&quot;yyyy-MM-dd 'at' HH:mm:ss z&quot;);\n         date = new Date(System.currentTimeMillis());\n    }\n    public static void main(String[] args) {\n        getTime();\n    }\n    public static void  getTime(){\n        System.out.println(formatter.format(date));\n    }\n}<\/code><\/pre>\n<p>\u4ee5\u4e0a\u4f8b\u5b50\u662f \u7528\u6765\u83b7\u53d6\u5f53\u524d\u65f6\u95f4\uff0c\u5728\u8c03\u7528<code>getTime<\/code> \u9759\u6001\u65b9\u6cd5\u65f6\uff0c\u5b83\u4e0d\u4f1a\u91cd\u590d\u521b\u5efa<code>Date<\/code> <code>SimpleDateFormat<\/code><\/p>\n<p><strong>\u6267\u884c\u987a\u5e8f<\/strong>\uff1a \u4f18\u4e8e\u6784\u9020\u5668<\/p>\n<h4>1.3.5 <code>static<\/code> \u6ce8\u610f<\/h4>\n<ol>\n<li><code>static<\/code>\u5173\u952e\u5b57\u4e0d\u80fd\u4f1a\u6539\u53d8\u7c7b\u4e2d\u6210\u5458\u7684\u8bbf\u95ee\u6743\u9650\uff0c \u80fd\u6539\u53d8\u8bbf\u95ee\u6743\u9650\u53ea\u6709 <code>private<\/code>\u3001<code>public<\/code>\u3001<code>protected<\/code>.<\/li>\n<li>\n<p>\u901a\u8fc7 <code>this<\/code> \u53ef\u4ee5\u5728\u975e\u9759\u6001\u65b9\u6cd5\u4e2d\u662f\u53ef\u4ee5\u8bbf\u95ee\u9759\u6001\u65b9\u6cd5\u548c\u9759\u6001\u6210\u5458\u7684<\/p>\n<pre><code class=\"java\">public class Test {\n    private  static Date date ;\n    private  static SimpleDateFormat formatter;\n    private  static String name = &quot;\u524d\u7aef\u81ea\u5b66\u793e\u533a&quot;;\n    \n    public static void main(String[] args) {\n         Test test = new Test();\n         test.getStatic();\n    }\n    public static void func(){\n        System.out.println(&quot;\u6211\u662f\u9759\u6001\u65b9\u6cd5&quot;);\n    }\n    public  void getStatic(){\n        System.out.println(this.name);\n        this.func();\n    }\n}<\/code><\/pre>\n<p>\u4f8b\u5b50\u4e2d\uff0c\u5728\u975e\u9759\u6001\u65b9\u6cd5\u4e2d\uff0c\u53ef\u4ee5\u76f4\u63a5\u901a\u8fc7 <code>this<\/code> \u6765\u8fdb\u884c\u8bbf\u95ee\u7684\u9759\u6001\u65b9\u6cd5\u548c\u9759\u6001\u6210\u5458 \uff0c\u7136\u540e\u901a\u8fc7\u7c7b\u5b9e\u4f8b\u5316\u540e\uff0c\u5bf9\u8c61\u5373\u53ef\u901a\u8fc7\u975e\u9759\u6001\u65b9\u6cd5\u6765\u83b7\u53d6\u5230\u9759\u6001\u65b9\u6cd5\u4e2d\u5f97\u9759\u6001\u5c5e\u6027\u548c\u65b9\u6cd5\u3002<\/p>\n<\/li>\n<\/ol>\n<h3>1.4  \u62bd\u8c61\u7c7b <code>abstract<\/code><\/h3>\n<p>\u6211\u4eec\u5148\u6765\u4e86\u89e3\u4e00\u4e0b\u62bd\u8c61\u65b9\u6cd5\uff0c\u62bd\u8c61\u65b9\u6cd5\u662f\u4e00\u79cd\u7279\u6b8a\u7684\u65b9\u6cd5\uff1a<strong>\u5b83\u53ea\u6709\u58f0\u660e\uff0c\u800c\u6ca1\u6709\u5177\u4f53\u7684\u5b9e\u73b0<\/strong>\u3002<\/p>\n<p>\u62bd\u8c61\u65b9\u6cd5\u7684\u58f0\u660e\u683c\u5f0f\u4e3a\uff1a<\/p>\n<pre><code class=\"java\">abstract int getNum();<\/code><\/pre>\n<h4>1.4.1\u4f55\u4e3a \u62bd\u8c61\u7c7b \u5462 ?<\/h4>\n<p>\u88ab <code>abstract<\/code>\u5173\u952e\u8bcd\u4fee\u9970\u7684\u7c7b\u5c31\u662f\u62bd\u8c61\u7c7b\uff0c\u62bd\u8c61\u7c7b\u542b\u6709\u5c5e\u6027\u548c\u62bd\u8c61\u65b9\u6cd5\u3002<\/p>\n<p>\u62bd\u8c61\u7c7b\u4e2d\u542b\u6709\u65e0\u5177\u4f53\u5b9e\u73b0\u7684\u65b9\u6cd5\uff0c\u6240\u4ee5\u4e0d\u80fd\u7528\u62bd\u8c61\u7c7b\u521b\u5efa\u5bf9\u8c61\u3002<\/p>\n<p>\u5f53 \u5b50\u7c7b \u7ee7\u627f \u4e86 \u62bd\u8c61\u7c7b \uff0c<strong>\u90a3\u4e48\u5fc5\u987b\u7684\u5b9e\u73b0\u62bd\u8c61\u7c7b\u7684\u62bd\u8c61\u65b9\u6cd5\uff0c\u540c\u65f6 \u5b50\u7c7b\u7684\u5b9e\u4f8b\u5316\u5bf9\u8c61\u62e5\u6709\u62bd\u8c61\u7c7b\u7684\u5c5e\u6027<\/strong>\u3002<\/p>\n<pre><code class=\"java\">public abstract class Animal {\n    abstract String name;\n    abstract void eat();\n}<\/code><\/pre>\n<h4>1.4.2 \u62bd\u8c61\u7c7b\u4f5c\u7528\uff1f<\/h4>\n<p>\u62bd\u8c61\u7c7b\u4e3b\u8981\u7528\u6765\u62bd\u79bb\u4e8b\u7269\u7684\u5171\u6027\uff0c\u62bd\u79bb\u51fa\u5c5e\u6027\u548c\u65b9\u6cd5\uff0c\u5b50\u7c7b \u7ee7\u627f \u62bd\u8c61\u7c7b\uff0c\u63d0\u9ad8\u4ee3\u7801\u6548\u7387\u3002<\/p>\n<h4>1.4.3 \u62bd\u8c61\u7c7b\u4e0e\u666e\u901a\u7c7b\u533a\u522b<\/h4>\n<ol>\n<li>\u62bd\u8c61\u65b9\u6cd5\u5fc5\u987b\u4e3apublic\u6216\u8005protected\uff08\u56e0\u4e3a\u5982\u679c\u4e3aprivate\uff0c\u5219\u4e0d\u80fd\u88ab\u5b50\u7c7b\u7ee7\u627f\uff0c\u5b50\u7c7b\u4fbf\u65e0\u6cd5\u5b9e\u73b0\u8be5\u65b9\u6cd5\uff09\uff0c\u7f3a\u7701\u60c5\u51b5\u4e0b\u9ed8\u8ba4\u4e3apublic\u3002<\/li>\n<li>\u62bd\u8c61\u7c7b\u4e0d\u80fd\u7528\u6765\u521b\u5efa\u5bf9\u8c61\uff1b<\/li>\n<li>\u5982\u679c\u4e00\u4e2a\u7c7b\u7ee7\u627f\u4e8e\u4e00\u4e2a\u62bd\u8c61\u7c7b\uff0c<strong>\u5219\u5b50\u7c7b\u5fc5\u987b\u5b9e\u73b0\u7236\u7c7b\u7684\u62bd\u8c61\u65b9\u6cd5<\/strong>\u3002\u5982\u679c\u5b50\u7c7b\u6ca1\u6709\u5b9e\u73b0\u7236\u7c7b\u7684\u62bd\u8c61\u65b9\u6cd5\uff0c\u5219\u5fc5\u987b\u5c06\u5b50\u7c7b\u4e5f\u5b9a\u4e49\u4e3a\u4e3aabstract\u7c7b\u3002<\/li>\n<\/ol>\n<h3>1.5 \u63a5\u53e3 <code>interface<\/code><\/h3>\n<h4>1.5.1 \u4ec0\u4e48\u662f\u63a5\u53e3\uff1f<\/h4>\n<p>\u5b83\u662f\u5bf9\u884c\u4e3a\u7684\u62bd\u8c61\uff0c\u63a5\u53e3\u901a\u5e38\u4ee5<code>interface<\/code>\u6765\u58f0\u660e\u3002\u4e00\u4e2a\u7c7b\u901a\u8fc7\u7ee7\u627f\u63a5\u53e3\u7684\u65b9\u5f0f\uff0c\u4ece\u800c\u6765\u7ee7\u627f\u63a5\u53e3\u7684\u62bd\u8c61\u65b9\u6cd5\u3002<\/p>\n<p>\u5f53\u4e00\u4e2a\u7c7b\u9700\u8981\u7528\u5230\u8fd9\u4e9b\u62bd\u8c61\u884c\u4e3a\u7684\u8bdd\uff0c\u9700\u8981 \u5b9e\u73b0\u63a5\u53e3 <code>implements<\/code> , \u800c\u4e14\u5fc5\u987b\u5b9e\u73b0\u63a5\u53e3\u4e2d\u65b9\u6cd5\u3002<\/p>\n<pre><code class=\"java\">public interface person {\n    void study(){}  \n}<\/code><\/pre>\n<h4>1.5.2 \u63a5\u53e3\u7279\u6027<\/h4>\n<ol>\n<li>\n<p>\u63a5\u53e3\u4e2d\u6bcf\u4e00\u4e2a\u65b9\u6cd5\u4e5f\u662f\u9690\u5f0f\u62bd\u8c61\u7684,\u63a5\u53e3\u4e2d\u7684\u65b9\u6cd5\u4f1a\u88ab\u9690\u5f0f\u7684\u6307\u5b9a\u4e3a <code>public abstract<\/code>\uff08\u53ea\u80fd\u662f <code>public abstract<\/code>\uff0c\u5176\u4ed6\u4fee\u9970\u7b26\u90fd\u4f1a\u62a5\u9519\uff09\u3002  \u4e5f\u53ef\u4e0d\u5199\uff0c\u9ed8\u8ba4\u5c31\u662f<code>public abstract<\/code> \u3002<\/p>\n<pre><code class=\"java\">public interface Aniaml{\n    public abstract void eat(); \/\/ \u62bd\u8c61\u65b9\u6cd5 == \u7b49\u540c\u4e8e  void eat();\n}<\/code><\/pre>\n<\/li>\n<\/ol>\n<ol start=\"2\">\n<li>\u63a5\u53e3\u4e2d\u53ef\u4ee5\u542b\u6709\u53d8\u91cf\uff0c\u4f46\u662f\u63a5\u53e3\u4e2d\u7684\u53d8\u91cf\u4f1a\u88ab\u9690\u5f0f\u7684\u6307\u5b9a\u4e3a <code>public static final<\/code> \u53d8\u91cf\uff08\u5e76\u4e14\u53ea\u80fd\u662f public\uff0c\u7528 private \u4fee\u9970\u4f1a\u62a5\u7f16\u8bd1\u9519\u8bef\uff09\u3002<\/li>\n<li>\u63a5\u53e3\u4e2d\u7684\u65b9\u6cd5\u662f\u4e0d\u80fd\u5728\u63a5\u53e3\u4e2d\u5b9e\u73b0\u7684\uff0c\u53ea\u80fd\u7531\u5b9e\u73b0\u63a5\u53e3\u7684\u7c7b\u6765\u5b9e\u73b0\u63a5\u53e3\u4e2d\u7684\u65b9\u6cd5\u3002<\/li>\n<\/ol>\n<h4>1.5.4 \u63a5\u53e3\u7684\u4f5c\u7528<\/h4>\n<ol>\n<li>\u4f7f\u7528\u63a5\u53e3\u53ef\u4ee5\u7ee7\u627f\u8d85\u8fc7\u4e00\u4e2a\u4ee5\u4e0a\u7684\u6765\u6e90\uff0c\u8fd9\u6837\u53ef\u4ee5\u4e3a\u4e0d\u540c\u7684\u9700\u6c42\u7ec4\u5408\u51fa\u4e0d\u540c\u7684\u7ee7\u627f\u5c42\u6b21\u3002<\/li>\n<li>\u63a5\u53e3\u89c4\u8303\u4e86\u5b9e\u73b0\u7c7b\uff0c\u5fc5\u987b\u5b9e\u73b0\u7684\u65b9\u6cd5\u548c\u5c5e\u6027\u3002<\/li>\n<\/ol>\n<h3>1.6 \u63a5\u53e3\u4e0e\u62bd\u8c61\u7c7b<\/h3>\n<p>\u5728Java\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4e24\u79cd\u5f62\u5f0f\u6765\u4f53\u73b0<code>OOP<\/code>\u7684\u62bd\u8c61\uff1a<code>\u63a5\u53e3<\/code>\u548c<code>\u62bd\u8c61\u7c7b<\/code>,  \u5b83\u4fe9\u6709\u5f88\u591a\u76f8\u4f3c\u4e4b\u5904\u3002<\/p>\n<h4>1.6.1 \u63a5\u53e3\u4e0e\u62bd\u8c61 \u533a\u522b<\/h4>\n<ol>\n<li>\u62bd\u8c61\u7c7b\u53ef\u4ee5\u63d0\u4f9b\u6210\u5458\u65b9\u6cd5\u7684\u5b9e\u73b0\u7ec6\u8282\uff0c\u800c\u63a5\u53e3\u4e2d\u53ea\u80fd\u5b58\u5728<code>public abstract <\/code>\u65b9\u6cd5\uff1b<\/li>\n<li>\u62bd\u8c61\u7c7b\u4e2d\u7684\u6210\u5458\u53d8\u91cf\u53ef\u4ee5\u662f\u5404\u79cd\u7c7b\u578b\u7684\uff0c\u800c\u63a5\u53e3\u4e2d\u7684\u6210\u5458\u53d8\u91cf\u53ea\u80fd\u662f<code>public static final<\/code>\u7c7b\u578b\u7684\uff1b<\/li>\n<li>\u63a5\u53e3\u4e2d\u4e0d\u80fd\u542b\u6709\u9759\u6001\u4ee3\u7801\u5757\u4ee5\u53ca\u9759\u6001\u65b9\u6cd5\uff0c\u800c\u62bd\u8c61\u7c7b\u53ef\u4ee5\u6709\u9759\u6001\u4ee3\u7801\u5757\u548c\u9759\u6001\u65b9\u6cd5\uff1b<\/li>\n<li>\u4e00\u4e2a\u7c7b\u53ea\u80fd\u7ee7\u627f\u4e00\u4e2a\u62bd\u8c61\u7c7b\uff0c\u800c\u4e00\u4e2a\u7c7b\u5374\u53ef\u4ee5\u5b9e\u73b0\u591a\u4e2a\u63a5\u53e3\u3002<\/li>\n<li><code>interface<\/code>  \u63a5\u53e3 \u662f\u9488\u5bf9\u4e8b\u7269\u7684 \u884c\u4e3a [ \u65b9\u6cd5 ] \u6765\u8fdb\u884c\u62bd\u8c61\u7684\uff0c   \u800c \u62bd\u8c61\u7c7b \u662f\u9488\u5bf9\u4e8b\u7269\u7684\u5171\u6027\u6765 \u5bf9 \u884c\u4e3a \u548c  \u5c5e\u6027 \u6765\u8fdb\u884c\u62bd\u8c61\u7684\u3002<\/li>\n<\/ol>\n<h4>1.6.2 \u4f8b\u5b50<\/h4>\n<p><strong>\u63a5\u53e3 interface<\/strong><\/p>\n<pre><code class=\"java\">public interface PeopleInterface {\n    void eat();\n    void study();\n    void play();\n}\n<\/code><\/pre>\n<p><strong>\u62bd\u8c61\u7c7b  abstract<\/strong><\/p>\n<pre><code class=\"java\">public abstract class People {\n   String name = &quot;\u4eba\u7c7b&quot;;\n    abstract void watch();\n}<\/code><\/pre>\n<p><strong>\u5b50\u7c7b<\/strong><\/p>\n<pre><code class=\"java\">public class Test extends People implements PeopleInterface {\n    public static void main(String[] args) {\n        Test test = new Test(); \/\/ \u5b50\u7c7b\u62e5\u6709\u62bd\u8c61\u7c7b\u7684\u5c5e\u6027\n        System.out.println(test.name);\n        test.eat();\n    }\n\n    @Override\n    public void eat() {\n        System.out.println(&quot;\u5403\u7684\u529f\u80fd&quot;);\n    }\n\n    @Override\n    public void study() {\n        System.out.println(&quot;\u5b66\u4e60\u529f\u80fd&quot;);\n    }\n\n    @Override\n    public void play() {\n        System.out.println(&quot;\u73a9\u7684\u529f\u80fd&quot;);\n    }\n\n    @Override\n    void watch() {\n        System.out.println(&quot;\u770b\u7684\u529f\u80fd&quot;);\n    }\n\n}<\/code><\/pre>\n<p>\u4e0a\u9762\u4f8b\u5b50\u4e2d\u8bb2\u4e86 \u7c7b \u4e0e \u63a5\u53e3 \u62bd\u8c61\u7c7b\u4e4b\u95f4\u5173\u7cfb\u3002 \u9996\u5148 <code> Test<\/code> \u7c7b \u7ee7\u627f\u4e86 <code>People<\/code> \u62bd\u8c61\u7c7b\uff0c\u7136\u540e\u53c8 \u5b9e\u73b0\u4e86 <code>PeopleInterface<\/code> \u63a5\u53e3\u3002<\/p>\n<p>\u5b50\u7c7b\u7ee7\u627f \u62bd\u8c61\u7c7b\u7684\u540c\u65f6\uff0c\u5fc5\u987b\u5b9e\u73b0\u62bd\u8c61\u7c7b\u7684\u62bd\u8c61\u65b9\u6cd5\uff0c\u5b50\u7c7b\u5b9e\u4f8b\u5316\u65f6\uff0c\u62e5\u6709\u62bd\u8c61\u7c7b\u7684\u5c5e\u6027\u3002<\/p>\n<p>\u5b50\u7c7b\u5b9e\u73b0 \u63a5\u53e3\u7684\u540c\u65f6\uff0c \u5fc5\u987b\u5b9e\u73b0\u63a5\u53e3\u4e2d\u6240\u6709\u7684\u63a5\u53e3\u884c\u4e3a\u3002<\/p>\n<h2>\u7ed3\u8bed<\/h2>\n<p>\u4ee5\u4e0a\u662f\u5bf9<code>Java \u9762\u5411\u5bf9\u8c61<\/code> \u7684\u603b\u7ed3\u5206\u4eab\uff0c\u5e0c\u671b\u80fd\u5bf9\u4f60\u6709\u6240\u542f\u53d1\uff0c\u6b22\u8fce\u63d0\u51fa\u610f\u89c1\uff01<\/p>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000042517735\">https:\/\/segmentfault.com\/a\/1190000042517735<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u53c2\u4e0e\u4e86\u601d\u5426\u6280\u672f\u5f81\u6587\uff0c\u6b22\u8fce\u6b63\u5728\u9605\u8bfb\u7684\u4f60\u4e5f\u52a0\u5165\u3002 \u4ece\u4e8b\u524d\u7aef\u7684\u8fd9\u4e24\u5e74\u4e2d\uff0c\u4e5f\u63a5\u89e6\u4e86\u540e\u7aef\u9886\u57df\uff0c\u50cf PHP Node, [&hellip;]<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[],"tags":[],"class_list":["post-10006554","post","type-post","status-publish","format-standard","hentry"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10006554","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10006554"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10006554\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10006554"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10006554"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10006554"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}