{"id":620,"date":"2023-12-26T18:01:01","date_gmt":"2023-12-26T10:01:01","guid":{"rendered":""},"modified":"2023-12-26T18:01:01","modified_gmt":"2023-12-26T10:01:01","slug":"\u9762\u8bd5\u5b98\uff1aJava\u7684\u91cd\u5199\u548c\u91cd\u8f7d\u6709\u4ec0\u4e48\u533a\u522b\uff1f","status":"publish","type":"post","link":"https:\/\/mushiming.com\/620.html","title":{"rendered":"\u9762\u8bd5\u5b98\uff1aJava\u7684\u91cd\u5199\u548c\u91cd\u8f7d\u6709\u4ec0\u4e48\u533a\u522b\uff1f"},"content":{"rendered":"

\n <\/path> \n<\/svg> <\/p>\n

\u8001\u8bfb\u8005\u90fd\u77e5\u9053\u4e86\uff0c\u4e03\u5e74\u524d\uff0c\u6211\u4ece\u7f8e\u5973\u5f88\u591a\u7684\u82cf\u5dde\u56de\u5230\u7f8e\u5973\u66f4\u591a\u7684\u6d1b\u9633\uff08\u7f8e\u5316\u4e86\uff09\uff0c\u62b1\u7740\u4e00\u5e45\u201c\u4ece\u4e8c\u7ebf\u57ce\u5e02\u9000\u5c45\u4e09\u7ebf\u57ce\u5e02\u201d\u7684\u5fc3\u6001\uff0c\u6295\u4e86\u4e0d\u5c11\u7b80\u5386\uff0c\u4e5f\u201c\u7ea6\u8c08\u201d\u4e86\u4e0d\u5c11\u9762\u8bd5\u5b98\uff0c\u4f46\u4ec5\u6709\u4e24\u4e09\u4e2a\u4ee4\u6211\u611f\u5230\u6ee1\u610f\u3002\u5176\u4e2d\u6709\u4e00\u4f4d\u53eb\u8001\u9a6c\uff0c\u81f3\u4eca\u8fd8\u6d3b\u5728\u6211\u7684\u5fae\u4fe1\u901a\u8baf\u5f55\u91cc\u3002\u4ed6\u5f53\u65f6\u6254\u4e86\u4e00\u4e2a\u9762\u8bd5\u9898\u628a\u6211\u7838\u61f5\u4e86\uff1a\u201c\u738b\u4e8c\uff0cJava \u7684\u91cd\u5199\uff08Override\uff09\u548c\u91cd\u8f7d\uff08Overload\uff09\u6709\u4ec0\u4e48\u533a\u522b\uff1f<\/strong>\u201d<\/p>\n

\u90a3\u5e74\u6211\u4e8c\u5341\u4e09\u5c81\uff0c\u6b63\u503c\u9752\u6625\u5e74\u534e\uff0c\u5927\u7ea6\u5c31\u662f\u5468\u6770\u4f26\u53d1\u5e03\u300a\u516b\u5ea6\u7a7a\u95f4\u300b\u7684\u5e74\u7eaa\uff0c\u81ea\u8ba4\u4e3a\u6240\u6709\u7684\u9762\u8bd5\u9898\u90fd\u80fd\u5bf9\u7b54\u5982\u6d41\uff0c\u7ed3\u679c\u6ca1\u60f3\u5230\u554a\uff0c\u88ab\u201c\u5201\u96be\u201d\u4e86\u2014\u2014\u539f\u6765\u6d1b\u9633\u8fd9\u5757\u4e92\u8054\u7f51\u7684\u8352\u6f20\u4e5f\u6709\u6280\u672f\u4e13\u5bb6\u554a\u3002\u73b0\u5728\u56de\u60f3\u8d77\u6765\uff0c\u8138\u4e0a\u4e0d\u81ea\u89c9\u5730\u6cdb\u8d77\u4e86\u7f9e\u6127\u7684\u7ea2\u6655\uff1a\u4e3b\u8981\u662f\u81ea\u5df1\u5f53\u65f6\u592a\u83dc\u4e86\u3002\u4e0d\u7ba1\u600e\u4e48\u8bf4\uff0c\u4e03\u5e74\u65f6\u95f4\u8fc7\u53bb\u4e86\uff0c\u6211\u7684\u6280\u672f\u529f\u5e95\u5df2\u7ecf\u975e\u5e38\u624e\u5b9e\uff0c\u6709\u80fd\u529b\u5199\u7bc7\u6587\u7ae0\u5256\u6790\u4e00\u4e0b Java \u7684\u91cd\u5199\u548c\u91cd\u8f7d\u4e86\uff0c\u53ea\u8981\u80fd\u7ed9\u540e\u6765\u8005\u4e00\u4e9b\u53c2\u8003\uff0c\u6211\u5c31\u89c9\u5f97\u505a\u4e86\u5929\u5927\u7684\u5584\u4e8b\u3002<\/p>\n

\"\u9762\u8bd5\u5b98\uff1aJava\u7684\u91cd\u5199\u548c\u91cd\u8f7d\u6709\u4ec0\u4e48\u533a\u522b\uff1f<\/p>\n

\u597d\u4e86\uff0c\u8ba9\u6211\u4eec\u6765\u6b65\u5165\u6b63\u9898\u3002\u5148\u6765\u770b\u4e00\u6bb5\u91cd\u5199\u7684\u4ee3\u7801\u5427\u3002<\/p>\n

class<\/span> LaoWang<\/span>{ \n   <\/span>\n    public<\/span> void<\/span> write<\/span>(<\/span>)<\/span> { \n   <\/span>\n        System.<\/span>out.<\/span>println<\/span>(<\/span>\"\u8001\u738b\u5199\u4e86\u4e00\u672c\u300a\u57fa\u7763\u5c71\u4f2f\u7235\u300b\"<\/span>)<\/span>;<\/span>\n    }<\/span>\n}<\/span>\npublic<\/span> class<\/span> XiaoWang<\/span> extends<\/span> LaoWang<\/span> { \n   <\/span>\n    @Override<\/span>\n    public<\/span> void<\/span> write<\/span>(<\/span>)<\/span> { \n   <\/span>\n        System.<\/span>out.<\/span>println<\/span>(<\/span>\"\u5c0f\u738b\u5199\u4e86\u4e00\u672c\u300a\u8336\u82b1\u5973\u300b\"<\/span>)<\/span>;<\/span>\n    }<\/span>\n}<\/span>\n<\/code><\/pre>\n

\u91cd\u5199\u7684\u4e24\u4e2a\u65b9\u6cd5\u540d\u76f8\u540c\uff0c\u65b9\u6cd5\u53c2\u6570\u7684\u4e2a\u6570\u4e5f\u76f8\u540c\uff1b\u4e0d\u8fc7\u4e00\u4e2a\u65b9\u6cd5\u5728\u7236\u7c7b\u4e2d\uff0c\u53e6\u5916\u4e00\u4e2a\u5728\u5b50\u7c7b\u4e2d\u3002\u5c31\u597d\u50cf\u7236\u7c7b LaoWang \u6709\u4e00\u4e2a write()<\/code> \u65b9\u6cd5\uff08\u65e0\u53c2\uff09\uff0c\u65b9\u6cd5\u4f53\u662f\u5199\u4e00\u672c\u300a\u57fa\u7763\u5c71\u4f2f\u7235\u300b\uff1b\u5b50\u7c7b XiaoWang \u91cd\u5199\u4e86\u7236\u7c7b\u7684 write()<\/code> \u65b9\u6cd5\uff08\u65e0\u53c2\uff09\uff0c\u4f46\u65b9\u6cd5\u4f53\u662f\u5199\u4e00\u672c\u300a\u8336\u82b1\u5973\u300b\u3002<\/p>\n

\u6765\u5199\u4e00\u6bb5\u6d4b\u8bd5\u4ee3\u7801\u3002<\/p>\n

public<\/span> class<\/span> OverridingTest<\/span> { \n   <\/span>\n    public<\/span> static<\/span> void<\/span> main<\/span>(<\/span>String[<\/span>]<\/span> args)<\/span> { \n   <\/span>\n        LaoWang wang =<\/span> new<\/span> XiaoWang<\/span>(<\/span>)<\/span>;<\/span>\n        wang.<\/span>write<\/span>(<\/span>)<\/span>;<\/span>\n    }<\/span>\n}<\/span>\n<\/code><\/pre>\n

\u5927\u5bb6\u731c\u7ed3\u679c\u662f\u4ec0\u4e48\uff1f<\/p>\n

\u5c0f\u738b\u5199\u4e86\u4e00\u672c\u300a\u8336\u82b1\u5973\u300b\n<\/code><\/pre>\n

\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u4eec\u58f0\u660e\u4e86\u4e00\u4e2a\u7c7b\u578b\u4e3a LaoWang \u7684\u53d8\u91cf wang\u3002\u5728\u7f16\u8bd1\u671f\u95f4\uff0c\u7f16\u8bd1\u5668\u4f1a\u68c0\u67e5 LaoWang \u7c7b\u662f\u5426\u5305\u542b\u4e86 write()<\/code> \u65b9\u6cd5\uff0c\u53d1\u73b0 LaoWang \u7c7b\u6709\uff0c\u4e8e\u662f\u7f16\u8bd1\u901a\u8fc7\u3002\u5728\u8fd0\u884c\u671f\u95f4\uff0cnew \u4e86\u4e00\u4e2a XiaoWang \u5bf9\u8c61\uff0c\u5e76\u5c06\u5176\u8d4b\u503c\u7ed9 wang\uff0c\u6b64\u65f6 Java \u865a\u62df\u673a\u77e5\u9053 wang \u5f15\u7528\u7684\u662f XiaoWang \u5bf9\u8c61\uff0c\u6240\u4ee5\u8c03\u7528\u7684\u662f\u5b50\u7c7b XiaoWang \u4e2d\u7684 write()<\/code> \u65b9\u6cd5\u800c\u4e0d\u662f\u7236\u7c7b LaoWang \u4e2d\u7684 write()<\/code> \u65b9\u6cd5\uff0c\u56e0\u6b64\u8f93\u51fa\u7ed3\u679c\u4e3a\u201c\u5c0f\u738b\u5199\u4e86\u4e00\u672c\u300a\u8336\u82b1\u5973\u300b\u201d\u3002<\/p>\n

\u518d\u6765\u770b\u4e00\u6bb5\u91cd\u8f7d\u7684\u4ee3\u7801\u5427\u3002<\/p>\n

class<\/span> LaoWang<\/span>{ \n   <\/span>\n    public<\/span> void<\/span> read<\/span>(<\/span>)<\/span> { \n   <\/span>\n        System.<\/span>out.<\/span>println<\/span>(<\/span>\"\u8001\u738b\u8bfb\u4e86\u4e00\u672c\u300aWeb\u5168\u6808\u5f00\u53d1\u8fdb\u9636\u4e4b\u8def\u300b\"<\/span>)<\/span>;<\/span>\n    }<\/span>\n    \n    public<\/span> void<\/span> read<\/span>(<\/span>String bookname)<\/span> { \n   <\/span>\n        System.<\/span>out.<\/span>println<\/span>(<\/span>\"\u8001\u738b\u8bfb\u4e86\u4e00\u672c\u300a\"<\/span> +<\/span> bookname +<\/span> \"\u300b\"<\/span>)<\/span>;<\/span>\n    }<\/span>\n}<\/span>\n<\/code><\/pre>\n

\u91cd\u8f7d\u7684\u4e24\u4e2a\u65b9\u6cd5\u540d\u76f8\u540c\uff0c\u4f46\u65b9\u6cd5\u53c2\u6570\u7684\u4e2a\u6570\u4e0d\u540c\uff0c\u53e6\u5916\u4e5f\u4e0d\u6d89\u53ca\u5230\u7ee7\u627f\uff0c\u4e24\u4e2a\u65b9\u6cd5\u5728\u540c\u4e00\u4e2a\u7c7b\u4e2d\u3002\u5c31\u597d\u50cf\u7c7b LaoWang \u6709\u4e24\u4e2a\u65b9\u6cd5\uff0c\u540d\u5b57\u90fd\u662f read()<\/code>\uff0c\u4f46\u4e00\u4e2a\u6709\u53c2\u6570\uff08\u4e66\u540d\uff09\uff0c\u53e6\u5916\u4e00\u4e2a\u6ca1\u6709\uff08\u53ea\u80fd\u8bfb\u5199\u6b7b\u7684\u4e00\u672c\u4e66\uff09\u3002<\/p>\n

\u6765\u5199\u4e00\u6bb5\u6d4b\u8bd5\u4ee3\u7801\u3002<\/p>\n

public<\/span> class<\/span> OverloadingTest<\/span> { \n   <\/span>\n    public<\/span> static<\/span> void<\/span> main<\/span>(<\/span>String[<\/span>]<\/span> args)<\/span> { \n   <\/span>\n        LaoWang wang =<\/span> new<\/span> LaoWang<\/span>(<\/span>)<\/span>;<\/span>\n        wang.<\/span>read<\/span>(<\/span>)<\/span>;<\/span>\n        wang.<\/span>read<\/span>(<\/span>\"\u91d1\u74f6\u6885\"<\/span>)<\/span>;<\/span>\n    }<\/span>\n}<\/span>\n<\/code><\/pre>\n

\u8fd9\u7ed3\u679c\u5c31\u4e0d\u7528\u731c\u4e86\u3002\u53d8\u91cf wang \u7684\u7c7b\u578b\u4e3a LaoWang\uff0cwang.read()<\/code> \u8c03\u7528\u7684\u662f\u65e0\u53c2\u7684 read()<\/code> \u65b9\u6cd5\uff0c\u56e0\u6b64\u5148\u8f93\u51fa\u201c\u8001\u738b\u8bfb\u4e86\u4e00\u672c\u300aWeb\u5168\u6808\u5f00\u53d1\u8fdb\u9636\u4e4b\u8def\u300b\u201d\uff1bwang.read(\"\u91d1\u74f6\u6885\")<\/code> \u8c03\u7528\u7684\u662f\u6709\u53c2\u7684 read(bookname)<\/code> \u65b9\u6cd5\uff0c\u56e0\u6b64\u540e\u8f93\u51fa\u201c\u8001\u738b\u8bfb\u4e86\u4e00\u672c\u300a\u91d1\u74f6\u6885\u300b\u201d\u3002\u5728\u7f16\u8bd1\u671f\u95f4\uff0c\u7f16\u8bd1\u5668\u5c31\u77e5\u9053\u8fd9\u4e24\u4e2a read()<\/code> \u65b9\u6cd5\u65f6\u4e0d\u540c\u7684\uff0c\u56e0\u4e3a\u5b83\u4eec\u7684\u65b9\u6cd5\u7b7e\u540d\uff08=\u65b9\u6cd5\u540d\u79f0+\u65b9\u6cd5\u53c2\u6570\uff09\u4e0d\u540c\u3002<\/p>\n

\u7b80\u5355\u7684\u6765\u603b\u7ed3\u4e00\u4e0b\uff1a<\/p>\n

1\uff09\u7f16\u8bd1\u5668\u65e0\u6cd5\u51b3\u5b9a\u8c03\u7528\u54ea\u4e2a\u91cd\u5199\u7684\u65b9\u6cd5\uff0c\u56e0\u4e3a\u53ea\u4ece\u53d8\u91cf\u7684\u7c7b\u578b\u4e0a\u662f\u65e0\u6cd5\u505a\u51fa\u5224\u65ad\u7684\uff0c\u8981\u5728\u8fd0\u884c\u65f6\u624d\u80fd\u51b3\u5b9a\uff1b\u4f46\u7f16\u8bd1\u5668\u53ef\u4ee5\u660e\u786e\u5730\u77e5\u9053\u8be5\u8c03\u7528\u54ea\u4e2a\u91cd\u8f7d\u7684\u65b9\u6cd5\uff0c\u56e0\u4e3a\u5f15\u7528\u7c7b\u578b\u662f\u786e\u5b9a\u7684\uff0c\u53c2\u6570\u4e2a\u6570\u51b3\u5b9a\u4e86\u8be5\u8c03\u7528\u54ea\u4e2a\u65b9\u6cd5\u3002<\/p>\n

2\uff09\u591a\u6001\u9488\u5bf9\u7684\u662f\u91cd\u5199\uff0c\u800c\u4e0d\u662f\u91cd\u8f7d\u3002<\/p>\n

\"\u9762\u8bd5\u5b98\uff1aJava\u7684\u91cd\u5199\u548c\u91cd\u8f7d\u6709\u4ec0\u4e48\u533a\u522b\uff1f<\/p>\n

\u54ce\uff0c\u540e\u6094\u554a\uff0c\u65e9\u5e74\u6211\u8981\u662f\u80fd\u628a\u8fd9\u9053\u9762\u8bd5\u9898\u5403\u900f\u7684\u8bdd\uff0c\u4e5f\u4e0d\u7528\u88ab\u8001\u9a6c\u5201\u96be\u4e86\u3002\u541f\u4e00\u9996\u8bd7\u611f\u6168\u4e00\u4e0b\u4eba\u751f\u5427\u3002<\/p>\n

\n

\u9752\u9752\u56ed\u4e2d\u8475\uff0c\u671d\u9732\u5f85\u65e5\u665e\u3002
\u9633\u6625\u5e03\u5fb7\u6cfd\uff0c\u4e07\u7269\u751f\u5149\u8f89\u3002
\u5e38\u6050\u79cb\u8282\u81f3\uff0c\u711c\u9ec4\u534e\u53f6\u8870\u3002
\u767e\u5ddd\u4e1c\u5230\u6d77\uff0c\u4f55\u65f6\u590d\u897f\u5f52?
\u5c11\u58ee\u4e0d\u52aa\u529b\uff0c\u8001\u5927\u5f92\u4f24\u60b2<\/p>\n<\/blockquote>\n

\u53e6\u5916\uff0c\u6211\u60f3\u8981\u544a\u8bc9\u5927\u5bb6\u7684\u662f\uff0c\u91cd\u5199\uff08Override\uff09\u548c\u91cd\u8f7d\uff08Overload\uff09\u662f Java \u4e2d\u4e24\u4e2a\u975e\u5e38\u91cd\u8981\u7684\u6982\u5ff5\uff0c\u65b0\u624b\u7ecf\u5e38\u4f1a\u88ab\u5b83\u4eec\u4fe9\u8ff7\u60d1\uff0c\u56e0\u4e3a\u5b83\u4eec\u4fe9\u7684\u82f1\u6587\u540d\u5b57\u592a\u50cf\u4e86\uff0c\u4e2d\u6587\u7ffb\u8bd1\u4e5f\u53ea\u5dee\u4e00\u4e2a\u5b57\u3002\u96be\uff0c\u592a\u96be\u4e86\u3002<\/p>\n

\"\u9762\u8bd5\u5b98\uff1aJava\u7684\u91cd\u5199\u548c\u91cd\u8f7d\u6709\u4ec0\u4e48\u533a\u522b\uff1f<\/p>\n

\u597d\u4e86\uff0c\u6211\u4eb2\u7231\u7684\u8bfb\u8005\u670b\u53cb\uff0c\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\u4e86\u3002\u80fd\u770b\u5230\u8fd9\u91cc\u7684\u90fd\u662f\u6700\u4f18\u79c0\u7684\u7a0b\u5e8f\u5458\uff0c\u4e8c\u54e5\u5fc5\u987b\u8981\u4f38\u51fa\u5927\u62c7\u6307\u4e3a\u4f60\u70b9\u4e2a\u8d5e\ud83d\udc4d\u3002\u539f\u521b\u4e0d\u6613\uff0c\u5982\u679c\u89c9\u5f97\u6709\u70b9\u7528\u7684\u8bdd\uff0c\u8bf7\u4e0d\u8981\u541d\u556c\u4f60\u624b\u4e2d\u70b9\u8d5e\u7684\u6743\u529b\uff0c\u56e0\u4e3a\u8fd9\u5c06\u662f\u6211\u6700\u5f3a\u7684\u5199\u4f5c\u52a8\u529b\u3002\u6211\u4eec\u4e0b\u7bc7\u6587\u7ae0\u89c1\uff01<\/p>\n

\"\u9762\u8bd5\u5b98\uff1aJava\u7684\u91cd\u5199\u548c\u91cd\u8f7d\u6709\u4ec0\u4e48\u533a\u522b\uff1f<\/p>\n","protected":false},"excerpt":{"rendered":"\u9762\u8bd5\u5b98\uff1aJava\u7684\u91cd\u5199\u548c\u91cd\u8f7d\u6709\u4ec0\u4e48\u533a\u522b\uff1f\u8001\u8bfb\u8005\u90fd\u77e5\u9053\u4e86\uff0c\u4e03\u5e74\u524d\uff0c\u6211\u4ece\u7f8e\u5973\u5f88\u591a\u7684\u82cf\u5dde\u56de\u5230\u7f8e\u5973\u66f4\u591a\u7684\u6d1b\u9633\uff08\u7f8e\u5316\u4e86\uff09\uff0c\u62b1\u7740\u4e00\u5e45\u201c...","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\/620"}],"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=620"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/620\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=620"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=620"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=620"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}