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

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

Java\u2014\u91cd\u5199\u4e0e\u91cd\u8f7d\u7684\u533a\u522b<\/h2>\n

\u8fd9\u51e0\u5468\u5f00\u59cb\u770bJava\u7684\u77e5\u8bc6\uff0c\u53d1\u73b0\u6709\u4e00\u4e2a\u6709\u8da3\u7684\u73b0\u8c61\u5c31\u662f\uff0c\u524d\u4e24\u5929\u521a\u770b\u8fc7\u7684\u77e5\u8bc6\u70b9\uff0c\u8fc7\u4e00\u5929\u53c8\u5fd8\u6389\u4e86\u3002\u800c\u4e14\u5f88\u591a\u4e1c\u897f\u5806\u5728\u8111\u5b50\u91cc\u50cf\u6d46\u7cca\u4e00\u6837\u3002\u6240\u4ee5\u8fb9\u5b66\u4e60\u8fb9\u603b\u7ed3\u662f\u5f88\u91cd\u8981\u7684\uff0c\u4eca\u5929\u60f3\u5199\u4e00\u7bc7\u5173\u4e8e\u91cd\u5199\u548c\u91cd\u8f7d\u7684\u535a\u5ba2\uff0c\u4e3a\u4ec0\u4e48\uff1f\u56e0\u4e3a\u9762\u8bd5\u4f1a\u95ee\u554a\uff0c\u8fd9\u662f\u57fa\u7840\u4e2d\u6bd4\u8f83\u91cd\u8981\u7684\u5730\u65b9\uff0c\u4f46\u6211\u767e\u5ea6\u4e86\u51e0\u7bc7\u535a\u5ba2\u4e4b\u540e\u53d1\u73b0\u5199\u7684\u90fd\u5dee\u5f3a\u4eba\u610f\uff0c\u5404\u6709\u7f3a\u70b9\uff0c\u4f46\u662f\uff01\uff01\u8bbf\u95ee\u91cf\u90fd\u7279\u522b\u9ad8\uff0c\u6240\u4ee5\u6211\u51b3\u5b9a\u81ea\u5df1\u597d\u597d\u603b\u7ed3\u4e00\u7bc7\u81ea\u5df1\u7684\u535a\u5ba2\uff0c\u4e5f\u7b97\u662f\u7ed9\u81ea\u5df1\u7684\u5b66\u4e60\u4e4b\u8def\u505a\u8bb0\u5f55\u3002<\/h3>\n
\n

1.\u91cd\u5199(Override)<\/h2>\n

\u4ece\u5b57\u9762\u4e0a\u770b\uff0c\u91cd\u5199\u5c31\u662f \u91cd\u65b0\u5199\u4e00\u904d\u7684\u610f\u601d\u3002\u5176\u5b9e\u5c31\u662f\u5728\u5b50\u7c7b\u4e2d\u628a\u7236\u7c7b\u672c\u8eab\u6709\u7684\u65b9\u6cd5<\/strong>\u91cd\u65b0\u5199\u4e00\u904d\u3002\u5b50\u7c7b\u7ee7\u627f\u4e86\u7236\u7c7b\u539f\u6709\u7684\u65b9\u6cd5\uff0c\u4f46\u6709\u65f6\u5b50\u7c7b\u5e76\u4e0d\u60f3\u539f\u5c01\u4e0d\u52a8\u7684\u7ee7\u627f\u7236\u7c7b\u4e2d\u7684\u67d0\u4e2a\u65b9\u6cd5\uff0c\u6240\u4ee5\u5728\u65b9\u6cd5\u540d\uff0c\u53c2\u6570\u5217\u8868\uff0c\u8fd4\u56de\u7c7b\u578b(\u9664\u8fc7\u5b50\u7c7b\u4e2d\u65b9\u6cd5\u7684\u8fd4\u56de\u503c\u662f\u7236\u7c7b\u4e2d\u65b9\u6cd5\u8fd4\u56de\u503c\u7684\u5b50\u7c7b\u65f6)\u90fd\u76f8\u540c\u7684\u60c5\u51b5\u4e0b\uff0c<\/strong> \u5bf9\u65b9\u6cd5\u4f53\u8fdb\u884c\u4fee\u6539\u6216\u91cd\u5199\uff0c\u8fd9\u5c31\u662f\u91cd\u5199\u3002\u4f46\u8981\u6ce8\u610f\u5b50\u7c7b\u51fd\u6570\u7684\u8bbf\u95ee\u4fee\u9970\u6743\u9650\u4e0d\u80fd\u5c11\u4e8e\u7236\u7c7b\u7684\u3002<\/strong>
\u4f8b\u5982\uff1a<\/strong><\/p>\n

public<\/span> class<\/span> Father<\/span> { \n   <\/span>\n\n    public<\/span> static<\/span> void<\/span> main(String[] args) {\n        \/\/ TODO Auto-generated method stub<\/span>\n        Son s = new<\/span> Son();\n        s.sayHello();\n    }\n\n    public<\/span> void<\/span> sayHello() {\n        System.out.println(\"Hello\"<\/span>);\n    }\n}\n\nclass<\/span> Son<\/span> extends<\/span><\/span> Father<\/span>{ \n   <\/span>\n\n    @Override\n    public<\/span> void<\/span> sayHello() {\n        \/\/ TODO Auto-generated method stub<\/span>\n        System.out.println(\"hello by \"<\/span>);\n    }\n\n}<\/code><\/pre>\n

\u91cd\u5199 \u603b\u7ed3\uff1a<\/strong>
1.\u53d1\u751f\u5728\u7236\u7c7b\u4e0e\u5b50\u7c7b\u4e4b\u95f4
2.\u65b9\u6cd5\u540d\uff0c\u53c2\u6570\u5217\u8868\uff0c\u8fd4\u56de\u7c7b\u578b\uff08\u9664\u8fc7\u5b50\u7c7b\u4e2d\u65b9\u6cd5\u7684\u8fd4\u56de\u7c7b\u578b\u662f\u7236\u7c7b\u4e2d\u8fd4\u56de\u7c7b\u578b\u7684\u5b50\u7c7b\uff09\u5fc5\u987b\u76f8\u540c
3.\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)
4.\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<\/p>\n


\n

2.\u91cd\u8f7d(Overload)<\/h2>\n

\u5728\u4e00\u4e2a\u7c7b\u4e2d\uff0c\u540c\u540d\u7684\u65b9\u6cd5\u5982\u679c\u6709\u4e0d\u540c\u7684\u53c2\u6570\u5217\u8868\uff08\u53c2\u6570\u7c7b\u578b\u4e0d\u540c\u3001\u53c2\u6570\u4e2a\u6570\u4e0d\u540c\u751a\u81f3\u662f\u53c2\u6570\u987a\u5e8f\u4e0d\u540c<\/strong>\uff09\u5219\u89c6\u4e3a\u91cd\u8f7d\u3002\u540c\u65f6\uff0c\u91cd\u8f7d\u5bf9\u8fd4\u56de\u7c7b\u578b\u6ca1\u6709\u8981\u6c42\uff0c\u53ef\u4ee5\u76f8\u540c\u4e5f\u53ef\u4ee5\u4e0d\u540c\uff0c\u4f46\u4e0d\u80fd\u901a\u8fc7\u8fd4\u56de\u7c7b\u578b\u662f\u5426\u76f8\u540c\u6765\u5224\u65ad\u91cd\u8f7d<\/strong>\u3002
\u4f8b\u5982\uff1a<\/strong><\/p>\n

public<\/span> class<\/span> Father {\n\n    public<\/span> static<\/span> void<\/span> main<\/span>(String[] args) {\n        \/\/ TODO Auto-generated method stub<\/span>\n        Father s = new<\/span> Father();\n        s.sayHello();\n        s.sayHello(\"wintershii\"<\/span>);\n\n    }\n\n    public<\/span> void<\/span> sayHello<\/span>() {\n        System.out<\/span>.println(\"Hello\"<\/span>);\n    }\n\n    public<\/span> void<\/span> sayHello<\/span>(String name) {\n        System.out<\/span>.println(\"Hello\"<\/span> + \" \"<\/span> + name);\n    }\n}<\/code><\/pre>\n

\u91cd\u8f7d \u603b\u7ed3\uff1a<\/strong>
1.\u91cd\u8f7dOverload\u662f\u4e00\u4e2a\u7c7b\u4e2d\u591a\u6001\u6027\u7684\u4e00\u79cd\u8868\u73b0
2.\u91cd\u8f7d\u8981\u6c42\u540c\u540d\u65b9\u6cd5\u7684\u53c2\u6570\u5217\u8868\u4e0d\u540c(\u53c2\u6570\u7c7b\u578b\uff0c\u53c2\u6570\u4e2a\u6570\u751a\u81f3\u662f\u53c2\u6570\u987a\u5e8f)
3.\u91cd\u8f7d\u7684\u65f6\u5019\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<\/p>\n


\n

\u9762\u8bd5\u65f6\uff0c\u95ee\uff1a\u91cd\u8f7d\uff08Overload\uff09\u548c\u91cd\u5199\uff08Override\uff09\u7684\u533a\u522b\uff1f<\/h3>\n
\n

\u7b54\uff1a\u65b9\u6cd5\u7684\u91cd\u8f7d\u548c\u91cd\u5199\u90fd\u662f\u5b9e\u73b0\u591a\u6001\u7684\u65b9\u5f0f\uff0c\u533a\u522b\u5728\u4e8e\u524d\u8005\u5b9e\u73b0\u7684\u662f\u7f16\u8bd1\u65f6\u7684\u591a\u6001\u6027\uff0c\u800c\u540e\u8005\u5b9e\u73b0\u7684\u662f\u8fd0\u884c\u65f6\u7684\u591a\u6001\u6027\u3002\u91cd\u8f7d\u53d1\u751f\u5728\u4e00\u4e2a\u7c7b\u4e2d\uff0c\u540c\u540d\u7684\u65b9\u6cd5\u5982\u679c\u6709\u4e0d\u540c\u7684\u53c2\u6570\u5217\u8868\uff08\u53c2\u6570\u7c7b\u578b\u4e0d\u540c\u3001\u53c2\u6570\u4e2a\u6570\u4e0d\u540c\u6216\u8005\u4e8c\u8005\u90fd\u4e0d\u540c\uff09\u5219\u89c6\u4e3a\u91cd\u8f7d\uff1b\u91cd\u5199\u53d1\u751f\u5728\u5b50\u7c7b\u4e0e\u7236\u7c7b\u4e4b\u95f4\uff0c\u91cd\u5199\u8981\u6c42\u5b50\u7c7b\u88ab\u91cd\u5199\u65b9\u6cd5\u4e0e\u7236\u7c7b\u88ab\u91cd\u5199\u65b9\u6cd5\u6709\u76f8\u540c\u7684\u53c2\u6570\u5217\u8868\uff0c\u6709\u517c\u5bb9\u7684\u8fd4\u56de\u7c7b\u578b\uff0c\u6bd4\u7236\u7c7b\u88ab\u91cd\u5199\u65b9\u6cd5\u66f4\u597d\u8bbf\u95ee\uff0c\u4e0d\u80fd\u6bd4\u7236\u7c7b\u88ab\u91cd\u5199\u65b9\u6cd5\u58f0\u660e\u66f4\u591a\u7684\u5f02\u5e38\uff08\u91cc\u6c0f\u4ee3\u6362\u539f\u5219\uff09\u3002\u91cd\u8f7d\u5bf9\u8fd4\u56de\u7c7b\u578b\u6ca1\u6709\u7279\u6b8a\u7684\u8981\u6c42\uff0c\u4e0d\u80fd\u6839\u636e\u8fd4\u56de\u7c7b\u578b\u8fdb\u884c\u533a\u5206\u3002<\/h4>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"Java\u2014\u91cd\u5199\u4e0e\u91cd\u8f7d\u7684\u533a\u522bJava\u2014\u91cd\u5199\u4e0e\u91cd\u8f7d\u7684\u533a\u522b\u8fd9\u51e0\u5468\u5f00\u59cb\u770bJava\u7684\u77e5\u8bc6\uff0c\u53d1\u73b0\u6709\u4e00\u4e2a\u6709\u8da3\u7684\u73b0\u8c61\u5c31\u662f\uff0c\u524d\u4e24\u5929\u521a\u770b\u8fc7\u7684\u77e5\u8bc6\u70b9\uff0c\u8fc7...","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\/631"}],"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=631"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/631\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=631"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=631"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=631"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}