{"id":617,"date":"2023-12-28T09:01:01","date_gmt":"2023-12-28T01:01:01","guid":{"rendered":""},"modified":"2023-12-28T09:01:01","modified_gmt":"2023-12-28T01:01:01","slug":"\u91cd\u8f7d\u4e0e\u91cd\u5199\u7684\u533a\u522b","status":"publish","type":"post","link":"https:\/\/mushiming.com\/617.html","title":{"rendered":"\u91cd\u8f7d\u4e0e\u91cd\u5199\u7684\u533a\u522b"},"content":{"rendered":"

\u91cd\u8f7d(Overloading)<\/span><\/p>\n

 \u65b9\u6cd5\u91cd\u8f7d\u662f\u8ba9\u7c7b\u4ee5\u7edf\u4e00\u7684\u65b9\u5f0f\u5904\u7406\u4e0d\u540c\u7c7b\u578b\u6570\u636e\u7684\u4e00\u79cd\u624b\u6bb5\u3002\u591a\u4e2a\u540c\u540d\u51fd\u6570\u540c\u65f6\u5b58\u5728\uff0c\u5177\u6709\u4e0d\u540c\u7684\u53c2\u6570\u4e2a\u6570\/\u7c7b\u578b\u3002<\/span><\/span><\/p>\n

\u91cd\u8f7dOverloading\u662f\u4e00\u4e2a\u7c7b\u4e2d\u591a\u6001\u6027\u7684\u4e00\u79cd\u8868\u73b0\u3002<\/span><\/span><\/p>\n

 Java\u7684\u65b9\u6cd5\u91cd\u8f7d\uff0c\u5c31\u662f\u5728\u7c7b\u4e2d\u53ef\u4ee5\u521b\u5efa\u591a\u4e2a\u65b9\u6cd5\uff0c\u5b83\u4eec\u5177\u6709\u76f8\u540c\u7684\u540d\u5b57\uff0c\u4f46\u5177\u6709\u4e0d\u540c\u7684\u53c2\u6570\u548c\u4e0d\u540c\u7684\u5b9a\u4e49\u3002<\/span><\/p>\n

\u8c03\u7528\u65b9\u6cd5\u65f6\u901a\u8fc7\u4f20\u9012\u7ed9\u5b83\u4eec\u7684\u4e0d\u540c\u53c2\u6570\u4e2a\u6570\u548c\u53c2\u6570\u7c7b\u578b\u6765\u51b3\u5b9a\u5177\u4f53\u4f7f\u7528\u54ea\u4e2a\u65b9\u6cd5, \u8fd9\u5c31\u662f\u591a\u6001\u6027\u3002<\/span><\/span><\/p>\n

 \u91cd\u8f7d\u7684\u65f6\u5019\uff0c\u65b9\u6cd5\u540d\u8981\u4e00\u6837\uff0c\u4f46\u662f\u53c2\u6570\u7c7b\u578b\u548c\u4e2a\u6570\u4e0d\u4e00\u6837\uff0c\u8fd4\u56de\u503c\u7c7b\u578b\u53ef\u4ee5\u76f8\u540c\u4e5f\u53ef\u4ee5\u4e0d\u76f8\u540c\u3002\u65e0\u6cd5\u4ee5\u8fd4\u56de\u578b\u522b\u4f5c\u4e3a\u91cd\u8f7d\u51fd\u6570\u7684\u533a\u5206\u6807\u51c6\u3002<\/span><\/p>\n


<\/span><\/p>\n

\u7236\u7c7b\u65b9\u6cd5\u88ab\u9ed8\u8ba4\u4fee\u9970\u65f6\uff0c\u53ea\u80fd\u5728\u540c\u4e00\u5305\u4e2d\uff0c\u88ab\u5176\u5b50\u7c7b\u88ab\u91cd\u5199\uff0c\u5982\u679c\u4e0d\u5728\u540c\u4e00\u5305\u5219\u4e0d\u80fd\u91cd\u5199\u3002<\/span><\/p>\n

\u7236<\/span>\u7c7b\u7684\u65b9\u6cd5\u88abprotoeted\u65f6\uff0c\u4e0d\u4ec5\u5728\u540c\u4e00\u5305\u4e2d\uff0c\u88ab\u5176\u5b50\u7c7b\u88ab\u91cd\u5199\uff0c\u8fd8\u53ef\u4ee5\u4e0d\u540c\u5305\u7684\u5b50\u7c7b\u91cd\u5199\u3002<\/span><\/p>\n

 <\/p>\n

\u91cd\u5199\u65b9\u6cd5\u7684\u89c4\u5219<\/span><\/span>\uff1a<\/span><\/span><\/p>\n

1\uff09\u3001\u53c2\u6570\u5217\u8868\u5fc5\u987b\u5b8c\u5168\u4e0e\u88ab\u91cd\u5199\u7684\u65b9\u6cd5\u76f8\u540c\uff0c\u5426\u5219\u4e0d\u80fd\u79f0\u5176\u4e3a\u91cd\u5199\u800c\u662f\u91cd\u8f7d\u3002<\/span><\/span><\/p>\n

2\uff09\u3001\u8fd4\u56de\u7684\u7c7b\u578b<\/span>\u5fc5\u987b\u4e00\u76f4\u4e0e\u88ab\u91cd\u5199\u7684\u65b9\u6cd5\u7684\u8fd4\u56de\u7c7b\u578b\u76f8\u540c<\/span>\uff0c\u5426\u5219\u4e0d\u80fd\u79f0\u5176\u4e3a\u91cd\u5199\u800c\u662f\u91cd\u8f7d\u3002<\/span><\/p>\n

3\uff09\u3001\u8bbf\u95ee\u4fee\u9970\u7b26\u7684\u9650\u5236\u4e00\u5b9a\u8981\u5927\u4e8e\u88ab\u91cd\u5199\u65b9\u6cd5\u7684\u8bbf\u95ee\u4fee\u9970\u7b26\uff08public>protected>default>private\uff09<\/span><\/p>\n

4\uff09\u3001\u91cd\u5199\u65b9\u6cd5\u4e00\u5b9a\u4e0d\u80fd\u629b\u51fa\u65b0\u7684\u68c0\u67e5\u5f02\u5e38\u6216\u8005\u6bd4\u88ab\u91cd\u5199\u65b9\u6cd5\u7533\u660e\u66f4\u52a0\u5bbd\u6cdb\u7684\u68c0\u67e5\u578b\u5f02\u5e38\u3002\u4f8b\u5982\uff1a<\/span><\/p>\n

\u7236\u7c7b\u7684\u4e00\u4e2a\u65b9\u6cd5\u7533\u660e\u4e86\u4e00\u4e2a\u68c0\u67e5\u5f02\u5e38IOException\uff0c\u5728\u91cd\u5199\u8fd9\u4e2a\u65b9\u6cd5\u662f\u5c31\u4e0d\u80fd\u629b\u51faException,\u53ea\u80fd\u629b\u51faIOException\u7684\u5b50\u7c7b\u5f02\u5e38\uff0c\u53ef\u4ee5\u629b\u51fa\u975e\u68c0\u67e5\u5f02\u5e38\u3002<\/span><\/p>\n

 <\/p>\n

\u800c\u91cd\u8f7d\u7684\u89c4\u5219\uff1a<\/span><\/p>\n

1\uff09\u3001\u5fc5\u987b\u5177\u6709\u4e0d\u540c\u7684\u53c2\u6570\u5217\u8868\uff1b<\/span><\/p>\n

2\uff09\u3001\u53ef\u4ee5\u6709\u4e0d\u540c\u7684\u8fd4\u56de\u7c7b\u578b\uff0c\u53ea\u8981\u53c2\u6570\u5217\u8868\u4e0d\u540c\u5c31\u53ef\u4ee5\u4e86\uff1b<\/span><\/p>\n

3\uff09\u3001\u53ef\u4ee5\u6709\u4e0d\u540c\u7684\u8bbf\u95ee\u4fee\u9970\u7b26\uff1b<\/span><\/p>\n

4\uff09\u3001\u53ef\u4ee5\u629b\u51fa\u4e0d\u540c\u7684\u5f02\u5e38\uff1b<\/span><\/p>\n


<\/span><\/p>\n

\u91cd\u8f7d\u548c\u91cd\u5199\uff08\u8986\u76d6\uff09\u7684\u7279\u70b9\uff1a<\/strong><\/span><\/p>\n


<\/strong><\/span><\/p>\n

<\/span><\/p>\n

1. Override \u7279\u70b9<\/span><\/p>\n

\u3000\u30001\u3001\u8986\u76d6\u7684\u65b9\u6cd5\u7684\u6807\u5fd7\u5fc5\u987b\u8981\u548c\u88ab\u8986\u76d6\u7684\u65b9\u6cd5\u7684\u6807\u5fd7\u5b8c\u5168\u5339\u914d\uff0c\u624d\u80fd\u8fbe\u5230\u8986\u76d6\u7684\u6548\u679c\uff1b<\/span><\/p>\n

\u3000\u30002\u3001\u8986\u76d6\u7684\u65b9\u6cd5\u7684\u8fd4\u56de\u503c\u5fc5\u987b\u548c\u88ab\u8986\u76d6\u7684\u65b9\u6cd5\u7684\u8fd4\u56de\u4e00\u81f4\uff1b<\/span><\/p>\n

\u3000\u30003\u3001\u8986\u76d6\u7684\u65b9\u6cd5\u6240\u629b\u51fa\u7684\u5f02\u5e38\u5fc5\u987b\u548c\u88ab\u8986\u76d6\u65b9\u6cd5\u7684\u6240\u629b\u51fa\u7684\u5f02\u5e38\u4e00\u81f4\uff0c\u6216\u8005\u662f\u5176\u5b50\u7c7b\uff1b<\/span><\/p>\n

\u3000\u30004\u3001\u88ab\u8986\u76d6\u7684\u65b9\u6cd5\u4e0d\u80fd\u4e3aprivate\uff0c\u5426\u5219\u5728\u5176\u5b50\u7c7b\u4e2d\u53ea\u662f\u65b0\u5b9a\u4e49\u4e86\u4e00\u4e2a\u65b9\u6cd5\uff0c\u5e76\u6ca1\u6709\u5bf9\u5176\u8fdb\u884c\u8986\u76d6\u3002<\/span><\/p>\n

2.Overload \u7279\u70b9<\/span><\/p>\n

\u3000\u30001\u3001\u5728\u4f7f\u7528\u91cd\u8f7d\u65f6\u53ea\u80fd\u901a\u8fc7\u4e0d\u540c\u7684\u53c2\u6570\u6837\u5f0f\u3002\u4f8b\u5982\uff0c\u4e0d\u540c\u7684\u53c2\u6570\u7c7b\u578b\uff0c\u4e0d\u540c\u7684\u53c2\u6570\u4e2a\u6570\uff0c\u4e0d\u540c\u7684\u53c2\u6570\u987a\u5e8f\uff08\u5f53\u7136\uff0c\u540c\u4e00\u65b9\u6cd5\u5185\u7684\u51e0\u4e2a\u53c2\u6570\u7c7b\u578b\u5fc5\u987b\u4e0d\u4e00\u6837\uff0c\u4f8b\u5982\u53ef\u4ee5\u662ffun(int, float)\uff0c \u4f46\u662f\u4e0d\u80fd\u4e3afun(int, int)\uff09\uff1b<\/span><\/p>\n

\u3000\u30002\u3001\u4e0d\u80fd\u901a\u8fc7\u8bbf\u95ee\u6743\u9650\u3001\u8fd4\u56de\u7c7b\u578b\u3001\u629b\u51fa\u7684\u5f02\u5e38\u8fdb\u884c\u91cd\u8f7d\uff1b<\/span><\/p>\n

\u3000\u30003\u3001\u65b9\u6cd5\u7684\u5f02\u5e38\u7c7b\u578b\u548c\u6570\u76ee\u4e0d\u4f1a\u5bf9\u91cd\u8f7d\u9020\u6210\u5f71\u54cd\uff1b<\/span><\/p>\n

\u3000\u30004\u3001\u5bf9\u4e8e\u7ee7\u627f\u6765\u8bf4\uff0c\u5982\u679c\u67d0\u4e00\u65b9\u6cd5\u5728\u7236\u7c7b\u4e2d\u662f\u8bbf\u95ee\u6743\u9650\u662fpriavte\uff0c\u90a3\u4e48\u5c31\u4e0d\u80fd\u5728\u5b50\u7c7b\u5bf9\u5176\u8fdb\u884c\u91cd\u8f7d\uff0c\u5982\u679c\u5b9a\u4e49\u7684\u8bdd\uff0c\u4e5f\u53ea\u662f\u5b9a\u4e49\u4e86\u4e00\u4e2a\u65b0\u65b9\u6cd5\uff0c\u800c\u4e0d\u4f1a\u8fbe\u5230\u91cd\u8f7d\u7684\u6548\u679c\u3002<\/span><\/p>\n

<\/p>\n


<\/span><\/p>\n

\u603b\u7ed3\uff1a<\/span><\/p>\n

<\/span><\/p>\n

override\uff08\u91cd\u5199\uff09<\/span><\/p>\n

\u3000\u3000 1\u3001\u65b9\u6cd5\u540d\u3001\u53c2\u6570\u3001\u8fd4\u56de\u503c\u76f8\u540c\u3002<\/span><\/p>\n

\u3000\u3000 2\u3001\u5b50\u7c7b\u65b9\u6cd5\u4e0d\u80fd\u7f29\u5c0f\u7236\u7c7b\u65b9\u6cd5\u7684\u8bbf\u95ee\u6743\u9650\u3002<\/span><\/p>\n

\u3000\u3000 3\u3001\u5b50\u7c7b\u65b9\u6cd5\u4e0d\u80fd\u629b\u51fa\u6bd4\u7236\u7c7b\u65b9\u6cd5\u66f4\u591a\u7684\u5f02\u5e38(\u4f46\u5b50\u7c7b\u65b9\u6cd5\u53ef\u4ee5\u4e0d\u629b\u51fa\u5f02\u5e38)\u3002<\/span><\/p>\n

\u3000\u3000 4\u3001\u5b58\u5728\u4e8e\u7236\u7c7b\u548c\u5b50\u7c7b\u4e4b\u95f4\u3002<\/span><\/p>\n

\u3000\u3000 5\u3001\u65b9\u6cd5\u88ab\u5b9a\u4e49\u4e3afinal\u4e0d\u80fd\u88ab\u91cd\u5199\u3002<\/span><\/p>\n

\u3000overload\uff08\u91cd\u8f7d\uff09<\/span><\/p>\n

\u3000\u30001\u3001\u53c2\u6570\u7c7b\u578b\u3001\u4e2a\u6570\u3001\u987a\u5e8f\u81f3\u5c11\u6709\u4e00\u4e2a\u4e0d\u76f8\u540c\u3002 <\/span><\/p>\n

\u3000\u30002\u3001\u4e0d\u80fd\u91cd\u8f7d\u53ea\u6709\u8fd4\u56de\u503c\u4e0d\u540c\u7684\u65b9\u6cd5\u540d\u3002<\/span><\/p>\n

\u3000\u30003\u3001\u5b58\u5728\u4e8e\u7236\u7c7b\u548c\u5b50\u7c7b\u3001\u540c\u7c7b\u4e2d\u3002<\/span><\/p>\n

<\/p>\n","protected":false},"excerpt":{"rendered":"\u91cd\u8f7d\u4e0e\u91cd\u5199\u7684\u533a\u522b\u91cd\u8f7d(Overloading)\u65b9\u6cd5\u91cd\u8f7d\u662f\u8ba9\u7c7b\u4ee5\u7edf\u4e00\u7684\u65b9\u5f0f\u5904\u7406\u4e0d\u540c\u7c7b\u578b\u6570\u636e\u7684\u4e00\u79cd\u624b\u6bb5\u3002\u591a\u4e2a\u540c\u540d\u51fd\u6570\u540c\u65f6\u5b58\u5728\uff0c\u5177\u6709\u4e0d\u540c...","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\/617"}],"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=617"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/617\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=617"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=617"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=617"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}