{"id":806,"date":"2019-10-28T11:17:50","date_gmt":"2019-10-28T03:17:50","guid":{"rendered":"http:\/\/47.101.202.111\/?p=806"},"modified":"2026-09-17T14:47:24","modified_gmt":"2026-09-17T06:47:24","slug":"java%e7%89%b9%e6%80%a7%e6%8a%bd%e8%b1%a1%e7%b1%bb%e5%92%8c%e6%8e%a5%e5%8f%a3","status":"publish","type":"post","link":"http:\/\/139.196.114.170\/?p=806","title":{"rendered":"[java\u7279\u6027]\u62bd\u8c61\u7c7b\u548c\u63a5\u53e3"},"content":{"rendered":"<p>[toc]<\/p>\n<h3>abstract\u5173\u952e\u5b57<\/h3>\n<p><strong>abstract\u4e0d\u53ef\u4e0efinal\u5173\u952e\u5b57\u540c\u65f6\u51fa\u73b0<\/strong><br \/>\nabstract\u5f3a\u5236\u7ee7\u627f\u548c\u8986\u5199\uff0cfinal\u7981\u6b62\u7ee7\u627f\u548c\u8986\u5199<br \/>\n<strong>abstract\u4e0d\u53ef\u4e0estatic\u5173\u952e\u5b57\u540c\u65f6\u51fa\u73b0<\/strong><br \/>\nabstract\u65b9\u6cd5\u65e0\u65b9\u6cd5\u4f53\u5b9e\u73b0\uff0cstatic\u4e0d\u53ef\u76f4\u63a5\u8c03\u7528\u672a\u5b9e\u73b0\u65b9\u6cd5<br \/>\n<strong>abstract\u4e0d\u53ef\u4e0eprivate\u5173\u952e\u5b57\u540c\u65f6\u51fa\u73b0<\/strong><br \/>\nabstract\u5f3a\u5236\u7ee7\u627f\u548c\u8986\u5199\uff0cprivate\u7c7b\u5916\u4e0d\u53ef\u89c1<br \/>\n<strong>abstract\u4e0d\u53ef\u4e0enative\u5173\u952e\u5b57\u540c\u65f6\u51fa\u73b0<\/strong><br \/>\n<strong>\u6784\u9020\u65b9\u6cd5\u4e0d\u53ef\u58f0\u660e\u4e3aabstract<\/strong><br \/>\nabstract\u65b9\u6cd5\u7531\u5b50\u7c7b\u5b9e\u73b0\uff0c\u4e0e\u5b50\u7c7b\u6784\u9020\u65b9\u6cd5\u547d\u540d\u51b2\u7a81<br \/>\n<strong>\u6210\u5458\u5c5e\u6027\u4e0d\u53ef\u58f0\u660e\u4e3aabstract<\/strong><\/p>\n<h3>\u62bd\u8c61\u7c7b<\/h3>\n<p>\u5b50\u7c7b\u7ee7\u627f\u666e\u901a\u7c7b\u65f6\u53ef\u4ee5\u4e0d\u8986\u5199\u67d0\u4e00\u65b9\u6cd5<br \/>\n\u62bd\u8c61\u7c7b\u5fc5\u987b\u88ab\u5b50\u7c7b\u7ee7\u627f\uff0c\u62bd\u8c61\u65b9\u6cd5\u5f3a\u5236\u5b50\u7c7b\u8986\u5199<br \/>\n\u62bd\u8c61\u7c7b\u7ee7\u627f\u62bd\u8c61\u7c7b\u65e0\u9700\u5168\u90e8\u8986\u5199\u62bd\u8c61\u65b9\u6cd5<br \/>\n\u62bd\u8c61\u5b50\u7c7b\u4e0d\u80fd\u6709\u4e0e\u7236\u7c7b\u540c\u540d\u62bd\u8c61\u65b9\u6cd5<br \/>\n\u666e\u901a\u5b50\u7c7b\u9700\u8981\u5b9e\u73b0\u6240\u6709\u7236\u7c7b\u62bd\u8c61\u65b9\u6cd5<br \/>\n\u62bd\u8c61\u7c7b\u53ef\u4ee5\u7ee7\u627f\u666e\u901a\u7c7b<\/p>\n<h4>\u62bd\u8c61\u7c7b\u4e2d\u7684\u6210\u5458<\/h4>\n<p>\u62bd\u8c61\u7c7b\u4e2d\u53ef\u4ee5\u5b9a\u4e49\u666e\u901a\/\u9759\u6001\u6210\u5458<br \/>\n\u62bd\u8c61\u7c7b\u4e2d\u7684\u6210\u5458\u5c5e\u6027\u4efb\u610f\u8bbf\u95ee\u6743\u9650<\/p>\n<h4>\u62bd\u8c61\u7c7b\u4e2d\u7684\u65b9\u6cd5<\/h4>\n<p>\u62bd\u8c61\u7c7b\u4e2d\u53ef\u5b9a\u4e49\u6784\u9020\u65b9\u6cd5\u4e3a\u6210\u5458\u8d4b\u503c<br \/>\n\u62bd\u8c61\u7c7b\u4e2d\u53ef\u4ee5\u5b9a\u4e49\u4efb\u610f\u6743\u9650\u666e\u901a\/\u9759\u6001\u65b9\u6cd5<br \/>\n\u62bd\u8c61\u65b9\u6cd5\u6ca1\u6709\u65b9\u6cd5\u4f53\u4e14\u6709\u8bbf\u95ee\u63a7\u5236\u6743\u9650<br \/>\n\u62bd\u8c61\u65b9\u6cd5\u8bbf\u95ee\u6743\u9650\u4e0d\u80fd\u4e3aprivate<br \/>\n\u62bd\u8c61\u5b50\u7c7b\u53ef\u8986\u5199\u7236\u62bd\u8c61\u7c7b\u65b9\u6cd5<\/p>\n<h4>\u62bd\u8c61\u7c7b\u5b9a\u4e49<\/h4>\n<pre lang=\"java\">\n    abstract class AbstractClassName {\n        public abstract void abstractMethod (int a);   \/\/ \u62bd\u8c61\u65b9\u6cd5\n        public void simpleMethod (int a) {             \/\/ \u666e\u901a\u65b9\u6cd5\n            this.abstractMethod (a); \/\/ \u666e\u901a\u65b9\u6cd5\u8c03\u7528\u5b50\u7c7b\u5b9e\u73b0\u62bd\u8c61\u65b9\u6cd5\n        }\n\n        private int a;                                 \/\/ \u666e\u901a\u6210\u5458\n        public AbstractClassName (int a){              \/\/ \u6784\u9020\u65b9\u6cd5\n            this.a = a;\n        }\n    }\n\n    public class ClassName extends AbstractClassName {\n        @Override\n        public void abstractMethod (int a) {\n            \/\/ \u65b9\u6cd5\u5b9e\u73b0\u4f53\n        }\n    }\n<\/pre>\n<h4>\u62bd\u8c61\u7c7b\u4f7f\u7528<\/h4>\n<p>\u62bd\u8c61\u7c7b\u65e0\u6cd5\u88ab\u76f4\u63a5\u5b9e\u4f8b\u5316\uff0c\u9700\u8981\u7531\u5b50\u7c7b\u5b9e\u4f8b\u5316\u5e76\u5411\u4e0a\u8f6c\u578b<br \/>\n\u62bd\u8c61\u7c7b\u4e2d\u53ef\u4ee5\u6ca1\u6709\u62bd\u8c61\u65b9\u6cd5\uff0c\u4f46\u4e0d\u53ef\u76f4\u63a5\u5b9e\u4f8b\u5316<\/p>\n<pre><code class=\"language-java\">    AbstractClassName className = new ClassName();\n    className.abstractMethod(3);\/\/ \u8c03\u7528\u5b50\u7c7b\u5b9e\u73b0\u7684\u62bd\u8c61\u65b9\u6cd5\n    className.simpleMethod(3);  \/\/ \u8c03\u7528\u7ee7\u627f\u7236\u7c7b\u7684\u666e\u901a\u65b9\u6cd5<\/code><\/pre>\n<h4>\u62bd\u8c61\u7c7b\u9690\u85cf\u5b50\u7c7b<\/h4>\n<pre><code class=\"language-java\">    public abstract class AbstractClassName {\n        public static AbstractClassName getInstance() {\n            return new ClassName();\n        }\n    }\n\n    class ClassName extends AbstractClassName {}<\/code><\/pre>\n<h3>\u7ee7\u627f extends<\/h3>\n<h4>\u53d8\u91cf\u5b58\u50a8\u4e0e\u8d4b\u503c<\/h4>\n<p>1\uff09\u7236\u7c7b\u5b9a\u4e49\u4f46\u5b50\u7c7b\u672a\u5b9a\u4e49\u7684\u53d8\u91cf 2\uff09\u7236\u7c7b\u5b9a\u4e49\u4f46\u5b50\u7c7b\u5b9a\u4e49\u540c\u7c7b\u578b\u540c\u540d\u53d8\u91cf\uff0c\u5b50\u7c7b\u5b9e\u4f8b\u5316\u5bf9\u8c61\u65f6\u4e3a\u53d8\u91cf\u5206\u914d\u5185\u5b58\uff08\u5373\u5b50\u7c7b\u5bf9\u8c61\u5355\u72ec\u6301\u6709\u53d8\u91cf\uff09\uff0c\u53d6\u503c\u903b\u8f91\u5982\u4e0b\uff1a<br \/>\n1\uff09\u4e2d\u5b50\u7c7b\u53d8\u91cf\u503c\u53d6\u7236\u7c7b\u53d8\u91cf\u8bbe\u7f6e\u503c\/\u9ed8\u8ba4\u503c<br \/>\n2\uff09\u4e2d\u5b50\u7c7b\u53d8\u91cf\u503c\u53d6\u5b50\u7c7b\u53d8\u91cf\u8bbe\u7f6e\u503c\/\u9ed8\u8ba4\u503c<\/p>\n<h3>\u63a5\u53e3<\/h3>\n<p>\u666e\u901a\u7c7b\/\u62bd\u8c61\u7c7b\u53ea\u80fd\u7ee7\u627f\u5355\u4e2a\u666e\u901a\u7c7b\/\u62bd\u8c61\u7c7b<br \/>\n\u666e\u901a\u7c7b\u548c\u62bd\u8c61\u7c7b\u53ef\u540c\u65f6implements\u591a\u4e2a\u63a5\u53e3<br \/>\n\u63a5\u53e3\u7684\u76ee\u7684\u662f\u5b9a\u4e49\u6807\u51c6\u548c\u89e3\u8026\u548c<br \/>\n\u63a5\u53e3\u4e0d\u662f\u7c7b\uff0c\u4e0d\u53ef\u7ee7\u627f\u4efb\u4f55\u4e00\u79cd\u7c7b<br \/>\n\u63a5\u53e3\u53ef\u4ee5\u540c\u65f6extends\u591a\u4e2a\u63a5\u53e3<br \/>\n\u63a5\u53e3\u4e2d\u4e00\u822c\u53ea\u5305\u542b\u5168\u5c40\u5e38\u91cf\u3001\u62bd\u8c61\u65b9\u6cd5<br \/>\n\u666e\u901a\u5b50\u7c7b\u5f3a\u5236\u8986\u5199\u6240\u6709\u7236\u63a5\u53e3\/\u62bd\u8c61\u7c7b\u7684\u6240\u6709\u62bd\u8c61\u65b9\u6cd5<br \/>\n\u62bd\u8c61\u5b50\u7c7b\/\u5b50\u63a5\u53e3\u65e0\u9700\u8986\u5199\u63a5\u53e3\u4e2d\u6240\u6709\u62bd\u8c61\u65b9\u6cd5<br \/>\n\u63a5\u53e3\u672c\u8eab\u662f\u62bd\u8c61\u7684\uff0c\u53ef\u7701\u53bbabstract\u5173\u952e\u5b57<\/p>\n<h4>\u63a5\u53e3\u4e2d\u7684\u6210\u5458<\/h4>\n<p>\u63a5\u53e3\u4e2d\u7684\u6210\u5458\u5c5e\u6027\u53ea\u80fd\u4e3apublic static final\uff0c\u5fc5\u987b\u8d4b\u521d\u503c<br \/>\n\u63a5\u53e3\u4e2d\u6210\u5458\u53ef\u7b80\u5199\u4e3a<strong>\u7c7b\u578b \u540d\u79f0 = \u521d\u503c;<\/strong><\/p>\n<h4>\u63a5\u53e3\u4e2d\u7684\u65b9\u6cd5<\/h4>\n<p>\u63a5\u53e3\u4e2d\u62bd\u8c61\u65b9\u6cd5\u58f0\u660e\u4e3apublic abstract\uff0c\u65e0\u65b9\u6cd5\u4f53<br \/>\n\u63a5\u53e3\u4e2d\u62bd\u8c61\u65b9\u6cd5\u53ef\u7b80\u5199\u4e3a<strong>\u8fd4\u56de\u503c \u65b9\u6cd5\u540d (\u53c2\u6570\u5217\u8868);<\/strong><br \/>\n\u666e\u901a\/\u62bd\u8c61\u5b50\u7c7b\u8986\u5199\u65b9\u6cd5\u540d\u79f0\u3001\u53c2\u6570\u3001\u8fd4\u56de\u503c\u4e0e\u63a5\u53e3\u76f8\u540c<br \/>\n\u666e\u901a\u5b50\u7c7b\u8986\u5199\u65b9\u6cd5\u8bbf\u95ee\u6743\u9650\u5927\u4e8e\u7b49\u4e8e\u63a5\u53e3\u65b9\u6cd5<br \/>\n\u63a5\u53e3\u4e2d\u9759\u6001\u65b9\u6cd5\u6743\u9650\u4ec5\u4e3apublic\uff0c\u6709\u65b9\u6cd5\u4f53<br \/>\n\u63a5\u53e3\u4e2d\u53ef\u5b9a\u4e49default\u9ed8\u8ba4\u65b9\u6cd5\uff0c\u6709\u65b9\u6cd5\u4f53<br \/>\n\u63a5\u53e3\u6ca1\u6709\u6784\u9020\u65b9\u6cd5<\/p>\n<h4>\u63a5\u53e3\u65b9\u6cd5\u91cd\u8f7d<\/h4>\n<p>\u540c\u4e00\u63a5\u53e3\u4e2d\u65b9\u6cd5\u53ef\u91cd\u8f7d<br \/>\n\u666e\u901a\u5b50\u7c7b\u540c\u65f6\u7ee7\u627f\u4e0d\u540c\u63a5\u53e3\/\u62bd\u8c61\u7c7b\u60c5\u51b5\u5982\u4e0b<\/p>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: left;\">\u65b9\u6cd5\u540d\u79f0<\/th>\n<th style=\"text-align: left;\">\u53c2\u6570\u5217\u8868<\/th>\n<th style=\"text-align: left;\">\u8fd4\u56de\u7c7b\u578b<\/th>\n<th style=\"text-align: left;\">\u5b50\u7c7b\u60c5\u51b5<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: left;\">\u76f8\u540c<\/td>\n<td style=\"text-align: left;\">\u76f8\u540c<\/td>\n<td style=\"text-align: left;\">\u76f8\u540c<\/td>\n<td style=\"text-align: left;\">\u5171\u7528\u540c\u4e00\u65b9\u6cd5<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">\u76f8\u540c<\/td>\n<td style=\"text-align: left;\">\u4e0d\u540c<\/td>\n<td style=\"text-align: left;\">\u76f8\u540c<\/td>\n<td style=\"text-align: left;\">\u65b9\u6cd5\u6b63\u786e\u91cd\u8f7d<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">\u76f8\u540c<\/td>\n<td style=\"text-align: left;\">\u76f8\u540c<\/td>\n<td style=\"text-align: left;\">\u4e0d\u540c<\/td>\n<td style=\"text-align: left;\">\u65e0\u6cd5\u901a\u8fc7\u7f16\u8bd1<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u5b50\u62bd\u8c61\u7c7b\u4e2d\u7684\u62bd\u8c61\u65b9\u6cd5\u4e0d\u80fd\u4e0e\u7236\u63a5\u53e3\u62bd\u8c61\u65b9\u6cd5\u91cd\u540d<br \/>\n\u5b50\u63a5\u53e3\u62bd\u8c61\u65b9\u6cd5\u4e0e\u7236\u63a5\u53e3\u62bd\u8c61\u65b9\u6cd5\u91cd\u540d\u5171\u7528\u540c\u4e00\u65b9\u6cd5<\/p>\n<h4>\u63a5\u53e3\u5b9a\u4e49<\/h4>\n<pre lang=\"java\">\n    public interface ICustomClass {\n        String str = \"string\";          \/\/ \u5168\u5c40\u5e38\u91cf\n        void interfaceMethod();         \/\/ \u62bd\u8c61\u65b9\u6cd5\n    }\n\n    public abstract class AbstractCustomClass {\n        public void abstractMethod();   \/\/ \u62bd\u8c61\u65b9\u6cd5\n    }\n\n    public CustomClassImpl [extends \u7236\u7c7b] implements [\u63a5\u53e31\uff0c\u63a5\u53e32] {\n        @Override\n        public void interfaceMethod(){} \/\/ \u5b9e\u73b0\u903b\u8f91\n        @Override\n        public void abstractMethod(){}  \/\/ \u5b9e\u73b0\u903b\u8f91\n    }\n<\/pre>\n<h4>\u63a5\u53e3\u4f7f\u7528<\/h4>\n<p>\u63a5\u53e3\u53ea\u80fd\u7531\u5b50\u7c7b\u5b9e\u4f8b\u5316\u5411\u4e0a\u8f6c\u578b<\/p>\n<pre><code class=\"language-java\">    ICustomClass cc = new CustomClass();\n    cc.interfaceMethod();<\/code><\/pre>\n<h4>\u63a5\u53e3\u6269\u5145<\/h4>\n<pre lang=\"java\">\n    public interface ICustomClass {\n        void methodA();\n        void methodB();             \/\/ \u65b0\u6269\u5145\u65b9\u6cd5\n    }\n\n    public class CustomClassA implements ICustomClass {\n        @Override\n        public void methodA() {}\n        @Override\n        public void methodB() {}    \/\/ \u5b9e\u73b0\u7c7b\u6269\u5145\n    }\n\n    public class CustomClassB implements ICustomClass {\n        @Override\n        public void methodA() {}\n        @Override\n        public void methodB() {}    \/\/ \u5b9e\u73b0\u7c7b\u6269\u5145\n    }\n<\/pre>\n<p>\u63a5\u53e3\u589e\u5220\u62bd\u8c61\u65b9\u6cd5\u9700\u8981\u4fee\u6539\u6240\u6709\u5b9e\u73b0\u5b50\u7c7b<br \/>\n\u540e\u671f\u4fee\u6539\u9020\u6210\u5927\u91cf\u53d8\u52a8\u95ee\u9898\u89e3\u51b3\u65b9\u6cd5\u5982\u4e0b<\/p>\n<p>\u2460 \u63a5\u53e3\u548c\u5b50\u7c7b\u4e4b\u95f4\u589e\u52a0\u62bd\u8c61\u7c7b<\/p>\n<pre><code class=\"language-java\">    public interface ICustomClass {\n        void methodA();\n        void methodB();             \/\/ \u65b0\u6269\u5145\u65b9\u6cd5\n    }\n\n    public abstract class AbstractCustomClass implements ICustomClass{\n        @Override\n        public void methodB() {}    \/\/ \u62bd\u8c61\u7c7b\u5b9e\u73b0\u5b50\u7c7b\u516c\u5171\u65b9\u6cd5\n    }\n\n    public class CustomClassA extends AbstractCustomClass implements ICustomClass {\n        @Override\n        public void methodA() {\n            super.methodB();        \/\/ \u516c\u5171\u65b9\u6cd5\u5b50\u5b9e\u73b0\u7c7b\u8c03\u7528\n        }\n    }\n\n    public class CustomClassB extends AbstractCustomClass implements ICustomClass {\n        @Override\n        public void methodA() {}\n        @Override\n        public void methodB() {}    \/\/ \u975e\u516c\u5171\u65b9\u6cd5\u4e2a\u6027\u5316\u8986\u5199\n    }<\/code><\/pre>\n<p>extends\u62bd\u8c61\u7c7b\u7ee7\u627f\u7236\u7c7b\u8986\u5199\u516c\u5171\u65b9\u6cd5\u903b\u8f91<br \/>\nimplements\u539f\u63a5\u53e3\u5f3a\u5236\u5b9e\u73b0\u6240\u6709\u62bd\u8c61\u65b9\u6cd5<br \/>\n\u6b64\u8bbe\u8ba1\u601d\u60f3\u5728List\u63a5\u53e3\u548c\u5b50\u7c7b\u8bbe\u8ba1\u4e2d\u4f53\u73b0<\/p>\n<p>\u2461 <strong>[JDK1.8]<\/strong> \u63a5\u53e3\u4e2d\u53ef\u5b9a\u4e49\u666e\u901a\u65b9\u6cd5\u548c\u9759\u6001\u65b9\u6cd5<\/p>\n<pre><code class=\"language-java\">    public interface ICustomClass {\n        public abstract void abstractMethod();  \/\/ \u62bd\u8c61\u65b9\u6cd5\n        public static void staticMethod() {}    \/\/ \u9759\u6001\u65b9\u6cd5\u903b\u8f91\n        default void plugInMethod() {}          \/\/ \u6269\u5145\u65b9\u6cd5\u903b\u8f91\n    }\n\n    public class CustomClass extends AbstractCustomClass {\n        @Override\n        public void abstractMethod() {\n            ICustomClass.staticMethod();        \/\/ \u9759\u6001\u65b9\u6cd5\n            this.plugInMethod();                \/\/ \u6269\u5145\u65b9\u6cd5\n        }\n    }<\/code><\/pre>\n<h4>\u63a5\u53e3\u89e3\u8026<\/h4>\n<p>\u63a5\u53e3\u5b9e\u73b0\u7c7b\u5747\u7b26\u5408\u63a5\u53e3\u6807\u51c6\u8bbe\u8ba1<br \/>\n\u66f4\u6539\u63a5\u53e3\u5b9e\u73b0\u7c7b\u65f6\u65e0\u9700\u6539\u6d4b\u8bd5\u7c7b<br \/>\n\u6d4b\u8bd5\u7c7b\u4ec5\u9700\u5173\u6ce8\u63a5\u53e3\u6807\u51c6\u7684\u4f7f\u7528<\/p>\n<h3>\u5f3a\u5236\u7c7b\u578b\u8f6c\u6362<\/h3>\n<p>\u540c\u4e00\u4e2a\u5b50\u7c7b\u5b9e\u4f8b\u7684\u4e0d\u540c\u7236\u7c7b\u548c\u63a5\u53e3\u4e4b\u95f4\u53ef\u4ee5\u5f3a\u5236\u7c7b\u578b\u8f6c\u6362<br \/>\n\u8f6c\u578b\u540e\u53ea\u80fd\u8c03\u7528\u76ee\u6807\u7c7b\u578b\u4e2d\u5b9a\u4e49\u7684\u65b9\u6cd5<\/p>\n<pre><code class=\"language-java\">    public interface ICustomClassA { void iMethodA(); }\n    public interface ICustomClassB { void iMethodB(); }\n    public abstract class AbstractCustom { abstract void aMethod(); }\n\n    public class Custom extends AbstractCustom\n    implements ICustomClassA, ICustomClassB {\n        @Override\n        public void iMethodA() { System.out.println(&quot;iMethodA&quot;); }\n        @Override\n        public void iMethodB() { System.out.println(&quot;iMethodB&quot;); }\n        @Override\n        public void aMethod() { System.out.println(&quot;aMethod&quot;); }\n    }\n\n    public class Test{\n        public static void main(String[] args) {\n            ICustomClassA iA = new Custom();\n            ICustomClassB iB = (ICustomClassB) iA;\n            AbstractCustom aC = (AbstractCustom) iB;\n            iA.iMethodA();\n            iB.iMethodB();\n            aC.aMethod();\n        }\n    }<\/code><\/pre>\n<pre><code>iMethodA\niMethodB\naMethod<\/code><\/pre>\n<p>\u63a5\u53e3\u5b9e\u4f8b\u540c\u4e3aObject\u548c\u63a5\u53e3\u5b50\u7c7b\uff0c\u53ef\u7528Object\u63a5\u6536<br \/>\nObject\u63a5\u6536\u540e\u5f3a\u8f6c\u7c7b\u578b\u53ef\u4f7f\u7528\u76ee\u6807\u7c7b\u578b\u5b9a\u4e49\u65b9\u6cd5<\/p>\n<pre><code class=\"language-java\">    ICustomClassA iA = new Custom();\n    Object obj = iA;\n    if(obj instanceof ICustomClassB){\n        ICustomClassB iB = (ICustomClassB) obj;\n        iB.iMethodB();\n    }<\/code><\/pre>\n<pre><code>iMethodB<\/code><\/pre>\n<h3>\u62bd\u8c61\u7c7b\u4e0e\u63a5\u53e3\u5bf9\u6bd4<\/h3>\n<table>\n<tr>\n<th>\u76f8\u540c<\/th>\n<th style=\"text-align:center;\">\u62bd\u8c61\u7c7b<\/th>\n<th style=\"text-align:center;\">\u63a5\u53e3<\/th>\n<\/tr>\n<tr>\n<td>\u4f5c\u7528<\/td>\n<td colspan=\"2\" style=\"text-align:center;\">\u5747\u5f3a\u5236\u5b50\u7c7b\u5b9e\u73b0abstract\u65b9\u6cd5<\/td>\n<\/tr>\n<tr>\n<td>\u5b9e\u4f8b\u5316<\/td>\n<td colspan=\"2\" style=\"text-align:center;\">\u5747\u9700\u5b50\u7c7b\u5b9e\u4f8b\u5316\u5411\u4e0a\u8f6c\u578b<\/td>\n<\/tr>\n<tr>\n<td>\u9759\u6001\u6210\u5458<\/td>\n<td colspan=\"2\" style=\"text-align:center;\">public static\u5747\u53ef\u901a\u8fc7\u7c7b\u540d\u8c03\u7528<\/td>\n<\/tr>\n<tr>\n<td>\u8bbf\u95ee\u6743\u9650<\/td>\n<td colspan=\"2\" style=\"text-align:center;\">\u5747\u4e0d\u53ef\u88ab\u4fee\u9970\u4e3afinal<\/td>\n<\/tr>\n<\/table>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: left;\">\u533a\u522b<\/th>\n<th style=\"text-align: left;\">\u62bd\u8c61\u7c7b<\/th>\n<th style=\"text-align: left;\">\u63a5\u53e3<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: left;\">\u5185\u5bb9<\/td>\n<td style=\"text-align: left;\">\u666e\u901a\/\u9759\u6001\u6210\u5458<br \/>\u666e\u901a\/\u9759\u6001\/\u62bd\u8c61\/\u6784\u9020\u65b9\u6cd5<br \/>\u6784\u9020\u5757\/\u9759\u6001\u5757<\/td>\n<td style=\"text-align: left;\">\u5168\u5c40\u5e38\u91cf<br \/>\u9759\u6001\/\u9ed8\u8ba4\/\u62bd\u8c61\u65b9\u6cd5<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">\u6743\u9650<\/td>\n<td style=\"text-align: left;\">\u6210\u5458\u975eprivate<\/td>\n<td style=\"text-align: left;\">\u6210\u5458\u5747public<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">\u5173\u952e\u5b57<\/td>\n<td style=\"text-align: left;\">abstract\u4e0d\u53ef\u7701\u7565<\/td>\n<td style=\"text-align: left;\">abstract\u53ef\u7701\u7565<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">\u7236\u7c7b<\/td>\n<td style=\"text-align: left;\">Object<\/td>\n<td style=\"text-align: left;\">\u65e0\u7236\u7c7b<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">\u7ee7\u627f<\/td>\n<td style=\"text-align: left;\">\u5355\u7ee7\u627f\uff0c\u53ef\u7ee7\u627f\u7c7b\u548c\u63a5\u53e3<\/td>\n<td style=\"text-align: left;\">\u591a\u7ee7\u627f\uff0c\u53ea\u53ef\u7ee7\u627f\u63a5\u53e3<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: left;\">\u8986\u5199<\/td>\n<td style=\"text-align: left;\">\u53ef\u8986\u5199\u65b9\u6cd5<\/td>\n<td style=\"text-align: left;\">\u4e0d\u53ef\u8986\u5199\u65b9\u6cd5<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>\u6a21\u677f\u65b9\u6cd5\u8bbe\u8ba1\u6a21\u5f0f<\/h3>\n<p>\u62bd\u8c61\u7236\u7c7b\u89c4\u5b9a\u65b9\u6cd5\u7684\u8c03\u7528\u987a\u5e8f<br \/>\n\u5b50\u7c7b\u5b9e\u73b0\u62bd\u8c61\u65b9\u6cd5\u7684\u5177\u4f53\u903b\u8f91<br \/>\n\u8c03\u5ea6\u65b9\u6cd5\u8bbe\u7f6efinal\u7981\u6b62\u91cd\u5199<\/p>\n<pre><code class=\"language-java\">    public abstract class AbstractCriteria {\n        public abstract void methodA();\n        public abstract void methodB();\n        public abstract void methodC();\n\n        public final void execute() {\n            this.methodA();\n            this.methodB();\n            this.methodC();\n        }\n    }\n\n    class Criteria extends AbstractCriteria {\n        @Override\n        public void methodA() {}\n        @Override\n        public void methodB() {}\n        @Override\n        public void methodC() {}\n    }\n\n    class TestDemo {\n        public static void main(String[] args) {\n            new Criteria().execute();\n        }\n    }<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>[toc] abstract\u5173\u952e\u5b57 abstract\u4e0d\u53ef\u4e0efinal\u5173\u952e\u5b57\u540c\u65f6\u51fa\u73b0 abstract\u5f3a\u5236\u7ee7\u627f\u548c &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/139.196.114.170\/?p=806\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201c[java\u7279\u6027]\u62bd\u8c61\u7c7b\u548c\u63a5\u53e3\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[25],"tags":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"http:\/\/139.196.114.170\/index.php?rest_route=\/wp\/v2\/posts\/806"}],"collection":[{"href":"http:\/\/139.196.114.170\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/139.196.114.170\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/139.196.114.170\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/139.196.114.170\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=806"}],"version-history":[{"count":23,"href":"http:\/\/139.196.114.170\/index.php?rest_route=\/wp\/v2\/posts\/806\/revisions"}],"predecessor-version":[{"id":3042,"href":"http:\/\/139.196.114.170\/index.php?rest_route=\/wp\/v2\/posts\/806\/revisions\/3042"}],"wp:attachment":[{"href":"http:\/\/139.196.114.170\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=806"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/139.196.114.170\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=806"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/139.196.114.170\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=806"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}