{"id":616,"date":"2023-12-28T18:01:01","date_gmt":"2023-12-28T10:01:01","guid":{"rendered":""},"modified":"2023-12-28T18:01:01","modified_gmt":"2023-12-28T10:01:01","slug":"\u65b9\u6cd5\u7684\u91cd\u8f7d\u548c\u91cd\u5199","status":"publish","type":"post","link":"https:\/\/mushiming.com\/616.html","title":{"rendered":"\u65b9\u6cd5\u7684\u91cd\u8f7d\u548c\u91cd\u5199"},"content":{"rendered":"

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

\u65b9\u6cd5\u7684\u91cd\u8f7d\u548c\u91cd\u5199<\/h1>\n

<\/font> <\/p>\n


\n <\/font> <\/p>\n
\n

<\/h3>\n
    \n
  • \u65b9\u6cd5\u7684\u91cd\u8f7d\u548c\u91cd\u5199<\/li>\n
  • \u524d\u8a00<\/li>\n
  • \u4e00\u3001\u65b9\u6cd5\u7684\u91cd\u8f7d(Overload)<\/li>\n
  • \n
      \n
    • 1.\u4e3a\u4ec0\u4e48\u8981\u4f7f\u7528\u65b9\u6cd5\u91cd\u8f7d<\/li>\n
    • 2.\u6ee1\u8db3\u65b9\u6cd5\u91cd\u8f7d\u7684\u6761\u4ef6<\/li>\n
    • 3.\u4e3e\u4f8b\u8bf4\u660e<\/li>\n<\/ul>\n<\/li>\n
    • \u4e8c\u3001\u65b9\u6cd5\u7684\u91cd\u5199(Override)<\/li>\n
    • \n
        \n
      • 1.\u4ec0\u4e48\u65f6\u5019\u8003\u8651\u65b9\u6cd5\u7684\u91cd\u5199<\/li>\n
      • 2.\u65b9\u6cd5\u91cd\u5199\u7684\u6761\u4ef6<\/li>\n
      • 3.\u6ce8\u610f\u4e8b\u9879<\/li>\n<\/ul>\n<\/li>\n
      • \u603b\u7ed3<\/li>\n<\/ul>\n<\/div>\n
        \n

        \u524d\u8a00<\/h1>\n

        \u65b9\u6cd5\u7684\u91cd\u8f7d\u548c\u91cd\u5199\u9700\u8981\u5927\u5bb6\u638c\u63e1 \uff0c\u5728\u7b14\u8bd5\u9762\u8bd5\u7684\u65f6\u5019\u53ef\u80fd\u95ee\u5230\u3002\u6211\u5728\u81ea\u5df1\u7684\u7406\u89e3\u4e0a\u505a\u4e86\u4e00\u4e0b\u603b\u7ed3\uff0c\u5e0c\u671b\u53ef\u4ee5\u5e2e\u52a9\u5927\u5bb6<\/font><\/p>\n


        \n <\/font> <\/p>\n

        \u4e00\u3001\u65b9\u6cd5\u7684\u91cd\u8f7d(Overload)<\/h1>\n

        <\/font> <\/p>\n

        1.\u4e3a\u4ec0\u4e48\u8981\u4f7f\u7528\u65b9\u6cd5\u91cd\u8f7d<\/h2>\n
        \n\u4e00\u4e9b\u529f\u80fd\u76f8\u4f3c\u7684\u65b9\u6cd5\u53ef\u4ee5\u5199\u6210\u540c\u6837\u7684\u65b9\u6cd5\u540d \n\u200b\u529f\u80fd\u4e0d\u540c\u7684\u65f6\u5019\uff0c\u5c3d\u53ef\u80fd\u8ba9\u65b9\u6cd5\u540d\u4e0d\u540c\u3002\n\n<\/code><\/pre>\n

        2.\u6ee1\u8db3\u65b9\u6cd5\u91cd\u8f7d\u7684\u6761\u4ef6<\/h2>\n
                     1.\u5728\u540c\u4e00\u4e2a\u7c7b\u4e2d\n             2.\u65b9\u6cd5\u540d\u76f8\u540c\n             3.\u5f62\u53c2\u5217\u8868\u4e0d\u540c(\u4e2a\u6570\uff0c\u7c7b\u578b\uff0c\u987a\u5e8f)\n             4.\u65b9\u6cd5\u7684\u91cd\u8f7d\u548c\u8fd4\u56de\u503c\u7c7b\u578b\u65e0\u5173\uff0c\u548c\u6743\u9650\u4fee\u9970\u7b26\u4e5f\u65e0\u5173\n<\/code><\/pre>\n

        3.\u4e3e\u4f8b\u8bf4\u660e<\/h2>\n

        1.\u65b9\u6cd5\u91cd\u8f7d\u4e3e\u4f8b
        \u4ee5\u4e0b\u7684\u65b9\u6cd5\u90fd\u6784\u6210\u91cd\u8f7d<\/p>\n

        public<\/span> void<\/span> getSum<\/span>(<\/span>int<\/span> i,<\/span>int<\/span> j)<\/span>{ \n   <\/span>\n\t\tSystem<\/span>.<\/span>out.<\/span>println<\/span>(<\/span>\"1\"<\/span>)<\/span>;<\/span>\n\t}<\/span>\n\t\n\tpublic<\/span> void<\/span> getSum<\/span>(<\/span>double<\/span> d1,<\/span>double<\/span> d2)<\/span>{ \n   <\/span>\n\t\tSystem<\/span>.<\/span>out.<\/span>println<\/span>(<\/span>\"2\"<\/span>)<\/span>;<\/span>\n\t}<\/span>\n\t\n\tpublic<\/span> void<\/span> getSum<\/span>(<\/span>String<\/span> s ,<\/span>int<\/span> i)<\/span>{ \n   <\/span>\n\t\tSystem<\/span>.<\/span>out.<\/span>println<\/span>(<\/span>\"3\"<\/span>)<\/span>;<\/span>\n\t}<\/span>\n\t\n\tpublic<\/span> void<\/span> getSum<\/span>(<\/span>int<\/span> i,<\/span>String<\/span> s)<\/span>{ \n   <\/span>\n\t\tSystem<\/span>.<\/span>out.<\/span>println<\/span>(<\/span>\"4\"<\/span>)<\/span>;<\/span>\n\t}<\/span>\n<\/code><\/pre>\n
          \n
        1. .\u4e0d\u80fd\u6784\u6210\u91cd\u8f7d\u4e3e\u4f8b<\/li>\n<\/ol>\n
          \t \n \tpublic<\/span> int<\/span> getSum<\/span>(<\/span>int<\/span> i,<\/span>int<\/span> j)<\/span>{ \n   <\/span>\n \t\treturn<\/span> 0<\/span>;<\/span>\n \t}<\/span>\n\t\n \tpublic<\/span> void<\/span> getSum<\/span>(<\/span>int<\/span> m,<\/span>int<\/span> n)<\/span>{ \n   <\/span>\n \t\t\n \t}<\/span>\n\t\n \tprivate<\/span> void<\/span> getSum<\/span>(<\/span>int<\/span> i,<\/span>int<\/span> j)<\/span>{ \n   <\/span>\n \t\t\n \t}<\/span>\n<\/code><\/pre>\n

          \u4e8c\u3001\u65b9\u6cd5\u7684\u91cd\u5199(Override)<\/h1>\n

          1.\u4ec0\u4e48\u65f6\u5019\u8003\u8651\u65b9\u6cd5\u7684\u91cd\u5199<\/h2>\n

          \u5b50\u7c7b\u7ee7\u627f\u7236\u7c7b\u4ee5\u540e\uff0c\u7ee7\u627f\u8fc7\u6765\u7684\u65b9\u6cd5\u4e0d\u80fd\u6ee1\u8db3\u5b50\u7c7b\u5f53\u524d\u7684\u4e1a\u52a1\u9700\u6c42\uff0c\u5b50\u7c7b\u6709\u6743\u5229\u5bf9\u8fd9\u4e2a\u65b9\u6cd5\u8fdb\u884c\u91cd\u65b0\u7f16\u5199\uff0c\u6709\u5fc5\u8981\u8fdb\u884c\u65b9\u6cd5\u7684\u8986\u76d6 <\/font> <\/p>\n

          2.\u65b9\u6cd5\u91cd\u5199\u7684\u6761\u4ef6<\/h2>\n
                     \u6761\u4ef6\u4e00\uff1a\u4e24\u4e2a\u7c7b\u8981\u6709\u7ee7\u627f\u5173\u7cfb\n           \u6761\u4ef6\u4e8c\uff1a\u91cd\u5199\u540e\u7684\u65b9\u6cd5\u548c\u4e4b\u524d\u7684\u65b9\u6cd5\u5177\u6709\uff1a\n                   \u76f8\u540c\u7684\u8fd4\u56de\u503c\u7c7b\u578b\n                   \u76f8\u540c\u7684\u65b9\u6cd5\u540d \n                   \u76f8\u540c\u7684\u5f62\u53c2\u5217\u8868 \n           \u6761\u4ef6\u4e09\uff1a\u91cd\u5199\u7684\u65b9\u6cd5\u7684\u8bbf\u95ee\u6743\u9650\u4e0d\u80fd\u66f4\u4f4e\n           \u6761\u4ef6\u56db\uff1a\u91cd\u5199\u4e4b\u540e\u7684\u65b9\u6cd5\u629b\u51fa\u7684\u5f02\u5e38\u7c7b\u578b\u4e0d\u80fd\u5927\u4e8e\u7236\u7c7b\u629b\u51fa\u7684\u5f02\u5e38\u7c7b\u578b\n<\/code><\/pre>\n

          \u200b<\/p>\n

          \u200b<\/p>\n

          \u65b9\u6cd5\u91cd\u5199\u7684\u4e3e\u4f8b<\/p>\n

          class<\/span> Circle<\/span>{ \n   <\/span>\npublic<\/span> double<\/span> findArea<\/span>(<\/span>)<\/span>{ \n   <\/span>}<\/span>\/\/\u6c42\u9762\u79ef<\/span>\n}<\/span>\nclass<\/span> Cylinder<\/span> extends<\/span> Circle<\/span>{ \n   <\/span>\npublic<\/span> double<\/span> findArea<\/span>(<\/span>)<\/span>{ \n   <\/span>}<\/span>\/\/\u6c42\u8868\u9762\u79ef<\/span>\n}<\/span>\n*<\/span>*<\/span>*<\/span>*<\/span>*<\/span>*<\/span>*<\/span>*<\/span>*<\/span>*<\/span>*<\/span>*<\/span>*<\/span>*<\/span>*<\/span>\nclass<\/span> Account<\/span>{ \n   <\/span>\npublic<\/span> boolean<\/span> withdraw<\/span>(<\/span>double<\/span> amt)<\/span>{ \n   <\/span>}<\/span>\n}<\/span>\nclass<\/span> CheckAccount<\/span> extends<\/span> Account<\/span>{ \n   <\/span>\npublic<\/span> boolean<\/span> withdraw<\/span>(<\/span>double<\/span> amt)<\/span>{ \n   <\/span>}<\/span>\n}<\/span>\n\n<\/code><\/pre>\n

          3.\u6ce8\u610f\u4e8b\u9879<\/h2>\n

          <\/font> <\/p>\n

          \u2460\u65b9\u6cd5\u8986\u76d6\u53ea\u662f\u9488\u5bf9\u65b9\u6cd5\uff0c\u548c\u5c5e\u6027\u65e0\u5173<\/p>\n

          \u2461\u79c1\u6709\u65b9\u6cd5\u4e0d\u80fd\u8986\u76d6<\/p>\n

          \u2462\u6784\u9020\u65b9\u6cd5\u4e0d\u80fd\u88ab\u7ee7\u627f\uff0c\u6240\u6709\u6784\u9020\u65b9\u6cd5\u4e5f\u4e0d\u80fd\u88ab\u8986\u76d6<\/p>\n

          \u2463\u65b9\u6cd5\u8986\u76d6\u53ea\u662f\u9488\u5bf9\u5b9e\u4f8b\u65b9\u6cd5\uff0c\u9759\u6001\u65b9\u6cd5\u8986\u76d6\u6ca1\u6709\u610f\u4e49<\/p>\n

          \u63a5\u4e0b\u6765\u662f\u6211\u7684\u4e00\u4e9b\u7406\u89e3<\/p>\n

          \n1.\u65b9\u6cd5\u7684\u8986\u76d6\u8981\u548c\u591a\u6001\u673a\u5236\u8054\u5408\u5728\u4e00\u8d77\u624d\u6709\u610f\u4e49\n    \u591a\u6001\u548c\u5bf9\u8c61\u6709\u5173\u7cfb\n    \u800c\u9759\u6001\u548c\u5bf9\u8c61\u6ca1\u6709\u5173\u7cfb\n    \u4e00\u822c\u60c5\u51b5\u4e0b\uff0c\u4e0d\u63a2\u8ba8\u9759\u6001\u65b9\u6cd5\u7684\u8986\u76d6\uff0c\u6211\u4eec\u4f1a\u8bf4\u9759\u6001\u65b9\u6cd5\u6ca1\u6709\u8986\u76d6\n    \u6ca1\u6709\u591a\u6001\u673a\u5236\u7684\u8bdd\uff0c\u65b9\u6cd5\u8986\u76d6\u53ef\u6709\u53ef\u65e0\n    \u5982\u679c\u6ca1\u6709\u591a\u6001\u673a\u5236\uff0c\u5f53\u7236\u7c7b\u7684\u65b9\u6cd5\u65e0\u6cd5\u6ee1\u8db3\u5b50\u7c7b\u9700\u6c42\u7684\u65f6\u5019\uff0c\n    \u6211\u4eec\u4e5f\u53ef\u4ee5\u5b9a\u4e49\u65b0\u7684\u65b9\u6cd5\n 2.\u79c1\u6709\u65b9\u6cd5\u4e0d\u80fd\u8986\u76d6\u5728\u5916\u90e8\u7c7b\u65e0\u6cd5\u8bbf\u95ee\u79c1\u6709\u7684\u65b9\u6cd5\n   \n     \u79c1\u6709\u65b9\u6cd5\u4f9b\u672c\u7c7b\u4f7f\u7528\n\n   \u53ef\u80fd\u6211\u4eec\u5728\u4e00\u4e2a\u7c7b\u5f53\u4e2d\u6709\u4e00\u4e9b\u5171\u540c\u7684\u64cd\u4f5c\uff0c\u6211\u4eec\u53ea\u5e0c\u671b\u8ba9\u5b83\u5728\u672c\u7c7b\u5f53\u4e2d\u8c03\u7528\uff0c\n   \u4e0d\u5e0c\u671b\u5b83\u5728\u5916\u90e8\u8c03\u7528\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u58f0\u660e\u4e3a\u79c1\u6709\u7684\u65b9\u6cd5\n\n\n3.\u8fd4\u56de\u503c\u7c7b\u578b\u53ef\u4ee5\u4e0d\u540c\u5417\n\u5bf9\u4e8e\u8fd4\u56de\u503c\u7c7b\u578b\u662f\u57fa\u672c\u6570\u636e\u7c7b\u578b\u6765\u8bf4\uff0c\u4e0d\u53ef\u4ee5\n\n\u5bf9\u4e8e\u8fd4\u56de\u503c\u7c7b\u578b\u662f\u5f15\u7528\u6570\u636e\u7c7b\u578b\u6765\u8bf4\uff0c\u91cd\u5199\u4e4b\u540e\u7684\u8fd4\u56de\u503c\u7c7b\u578b\u66f4\u5c0f\u662f\u53ef\u4ee5\u7684\n<\/code><\/pre>\n

          \"\u65b9\u6cd5\u7684\u91cd\u8f7d\u548c\u91cd\u5199
          \"\u65b9\u6cd5\u7684\u91cd\u8f7d\u548c\u91cd\u5199<\/p>\n

          \u603b\u7ed3<\/h1>\n

          \"\u65b9\u6cd5\u7684\u91cd\u8f7d\u548c\u91cd\u5199<\/p>\n","protected":false},"excerpt":{"rendered":"\u65b9\u6cd5\u7684\u91cd\u8f7d\u548c\u91cd\u5199\u65b9\u6cd5\u7684\u91cd\u8f7d\u548c\u91cd\u5199\u65b9\u6cd5\u7684\u91cd\u8f7d\u548c\u91cd\u5199\u524d\u8a00\u4e00\u3001\u65b9\u6cd5\u7684\u91cd\u8f7d(Overload)1.\u4e3a\u4ec0\u4e48\u8981\u4f7f\u7528\u65b9\u6cd5\u91cd\u8f7d2.\u6ee1\u8db3\u65b9\u6cd5\u91cd\u8f7d\u7684\u6761...","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\/616"}],"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=616"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/616\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=616"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=616"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=616"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}