{"id":619,"date":"2023-12-27T09:01:01","date_gmt":"2023-12-27T01:01:01","guid":{"rendered":""},"modified":"2023-12-27T09:01:01","modified_gmt":"2023-12-27T01:01:01","slug":"Java \u91cd\u8f7d\u548c\u91cd\u5199","status":"publish","type":"post","link":"https:\/\/mushiming.com\/619.html","title":{"rendered":"Java \u91cd\u8f7d\u548c\u91cd\u5199"},"content":{"rendered":"
\u76ee\u5f55<\/strong><\/p>\n \n \u4e00\u3001\u91cd\u5199(\u8986\u5199\/\u91cd\u5199\/\u8986\u76d6)<\/p>\n \u91cd\u5199\u7684\u89c4\u5219<\/p>\n \u5173\u4e8e\u91cd\u5199\u7684\u6ce8\u610f\u4e8b\u9879<\/p>\n \u4e8c\u3001\u91cd\u8f7d<\/p>\n \u91cd\u8f7d\u89c4\u5219\uff1a<\/p>\n \u91cd\u8f7d\uff08Overload\uff09\u548c\u91cd\u5199\uff08Override\uff09\u7684\u533a\u522b <\/p>\n \u5c31\u662f\u5728\u5b50\u7c7b\u4e2d\u628a\u7236\u7c7b\u672c\u8eab\u6709\u7684\u65b9\u6cd5\u91cd\u65b0\u5199\u4e00\u904d\u3002\u5b50\u7c7b\u7ee7\u627f\u4e86\u7236\u7c7b\u539f\u6709\u7684\u65b9\u6cd5\u3002<\/p>\n \u5b50\u7c7b\u8bbf\u95ee\u6743\u9650\u8981\u5927\u4e8e\u7236\u7c7b<\/strong><\/p>\n \u6709\u4e86\u8fd9\u4e2a\u6ce8\u89e3\u80fd\u5e2e\u6211\u4eec\u8fdb\u884c\u4e00\u4e9b\u5408\u6cd5\u6027\u6821\u9a8c. <\/span>\u4f8b\u5982\u4e0d\u5c0f\u5fc3\u5c06\u65b9\u6cd5\u540d\u5b57\u62fc\u5199\u9519\u4e86<\/span> (<\/span>\u6bd4\u5982\u5199\u6210<\/span> aet), <\/span>\u90a3\u4e48\u6b64\u65f6\u7f16\u8bd1\u5668\u5c31\u4f1a\u53d1 \u73b0\u7236\u7c7b\u4e2d\u6ca1\u6709 aet <\/span>\u65b9\u6cd5<\/span>, <\/span>\u5c31\u4f1a\u7f16\u8bd1\u62a5\u9519<\/span>, <\/span>\u63d0\u793a\u65e0\u6cd5\u6784\u6210\u91cd\u5199<\/span>.\u63d0\u9ad8\u4e86\u5199\u4ee3\u7801\u7684\u6548\u7387.<\/span><\/p>\n \u540c\u4e00\u4e2a\u65b9\u6cd5\u540d\u5b57\uff0c\u63d0\u4f9b\u4e0d\u540c\u7248\u672c\u7684\u5b9e\u73b0\uff0c\u79f0\u4e3a\u65b9\u6cd5\u91cd\u8f7d \u8865\u5145\uff1a\u6784\u9020\u65b9\u6cd5\u4e5f\u53ef\u4ee5\u91cd\u8f7d <\/span><\/p>\n<\/blockquote>\n \u5982\u4ee3\u7801\u4e2d\u4e00\u6837\uff0c\u901a\u8fc7\u4f20\u5165\u7684\u53c2\u6570\u7c7b\u578b\u4e0d\u540c\uff0c\u786e\u5b9a\u8c03\u7528\u54ea\u79cd\u7684\u91cd\u8f7d\u65b9\u6cd5\u3002<\/p>\n <\/p><\/p>\n","protected":false},"excerpt":{"rendered":"Java \u91cd\u8f7d\u548c\u91cd\u5199\u5c31\u662f\u5728\u5b50\u7c7b\u4e2d\u628a\u7236\u7c7b\u672c\u8eab\u6709\u7684\u65b9\u6cd5\u91cd\u65b0\u5199\u4e00\u904d\u3002\u5b50\u7c7b\u7ee7\u627f\u4e86\u7236\u7c7b\u539f\u6709\u7684\u65b9\u6cd5\u3002\u5982\u4ee3\u7801\u4e2d\u4e00\u6837\uff0c\u901a\u8fc7\u4f20\u5165\u7684\u53c2\u6570\u7c7b\u578b\u4e0d...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[82],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/619"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=619"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/619\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=619"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=619"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=619"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}
\n\u4e00\u3001\u91cd\u5199(\u8986\u5199\/\u91cd\u5199\/\u8986\u76d6)<\/h2>\n
\n
\n , <\/span>
\n \u5e76\u4e14\u53c2\u6570\u7684\u7c7b\u578b\u548c\u4e2a\u6570\u5b8c\u5168\u76f8\u540c<\/span><\/span>
\n , <\/span>
\n \u8fd9\u79cd\u60c5\u51b5\u79f0\u4e3a <\/span>
\n \u8986\u5199<\/strong><\/span>
\n \/<\/strong><\/span>
\n \u91cd\u5199<\/strong><\/span>
\n \/<\/strong><\/span>
\n \u8986\u76d6.<\/strong><\/span>\n <\/div>\n<\/blockquote>\n\u91cd\u5199\u7684\u89c4\u5219<\/h3>\n
\n
\u5173\u4e8e\u91cd\u5199\u7684\u6ce8\u610f\u4e8b\u9879 <\/strong><\/span><\/h3>\n
\n
\/\/ Animal.java \npublic class Animal { \n public void eat(String food) { \n ... \n } \n} \n\/\/ Bird.java \npublic class Bird extends Animal { \n \/\/ \u5c06\u5b50\u7c7b\u7684 eat \u6539\u6210 private \n private void eat(String food) { \n ... \n } \n} \n\/\/ \u7f16\u8bd1\u51fa\u9519\nError:(8, 10) java: com.bit.Bird\u4e2d\u7684eat(java.lang.String)\u65e0\u6cd5\u8986\u76d6com.bit.Animal\u4e2d\u7684\neat(java.lang.String) \n \u6b63\u5728\u5c1d\u8bd5\u5206\u914d\u66f4\u4f4e\u7684\u8bbf\u95ee\u6743\u9650; \u4ee5\u524d\u4e3apublic<\/code><\/pre>\n
\n \u663e\u5f0f\u52a0\u4e0a<\/span>
\n @Override <\/span>
\n \u6ce8\u89e3<\/span>
\n .<\/span>\n<\/div>\n\/\/ Bird.java \npublic class Bird extends Animal { \n @Override \n private void eat(String food) { \n ... \n } \n}<\/code><\/pre>\n
\u4e8c\u3001\u91cd\u8f7d<\/h2>\n
\n
\u91cd\u8f7d\u89c4\u5219\uff1a<\/h3>\n
\n
class Test{\n public static void main(String[] args) {\n int a=10;\n int b=20;\n int i=add(a,b);\n System.out.println(i);\n\n double a2=10.5;\n double b2=12.5;\n double i2=add(a2,b2);\n System.out.println(i2);\n }\n\n public static int add(int x,int y){\n return x+y;\n }\n\n public static double add(double x,double y){\n return x+y;\n }\n}\n\n\/\/\u7ed3\u679c\n30\n23<\/code><\/pre>\n
\u91cd\u8f7d\uff08Overload\uff09\u548c\u91cd\u5199\uff08Override\uff09\u7684\u533a\u522b <\/h3>\n