{"id":8421,"date":"2024-06-10T09:01:01","date_gmt":"2024-06-10T01:01:01","guid":{"rendered":""},"modified":"2024-06-10T09:01:01","modified_gmt":"2024-06-10T01:01:01","slug":"\u667a\u80fd\u5408\u7ea6\u5408\u7ea6\u5360\u6bd4_solidity\u667a\u80fd\u5408\u7ea6","status":"publish","type":"post","link":"https:\/\/mushiming.com\/8421.html","title":{"rendered":"\u667a\u80fd\u5408\u7ea6\u5408\u7ea6\u5360\u6bd4_solidity\u667a\u80fd\u5408\u7ea6"},"content":{"rendered":"

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

\u5927\u5bb6\u597d\uff0c\u8fd9\u91cc\u662f\u901a\u5b66\u6280\u672f\uff0c\u6b22\u8fce\u5927\u5bb6\u7ee7\u7eed\u8ddf\u6211\u4e00\u8d77\u5b66\u4e60\u667a\u80fd\u5408\u7ea6\u7cfb\u5217\u3002<\/p>\n

13\u3001\u9762\u5411\u5bf9\u8c61\u2013\u5408\u7ea6\u7684\u7ee7\u627f<\/h5>\n

\u76f8\u4fe1\u80fd\u770b\u5230\u8fd9\u91cc\u7684\u4eba\uff0c\u60f3\u5fc5\u90fd\u662f\u6709\u7ecf\u9a8c\u7684\u5f00\u53d1\u4eba\u5458\u4e86\uff0c\u575a\u6301\u4e0d\u61c8\uff0c\u8010\u5f97\u4f4f\u5bc2\u5bde\u3002<\/p>\n

solidity<\/code>\u4f5c\u4e3a\u4e00\u79cd\u56fe\u7075\u5b8c\u5907\u7684\u9762\u5411\u5bf9\u8c61\u7684\u7f16\u7a0b\u8bed\u8a00\uff0c\u5fc5\u7136\u540c\u5176\u4ed6\u9762\u5411\u5bf9\u8c61\u7684\u8bed\u8a00\u4e00\u6837\uff0c\u62e5\u6709\u7ee7\u627f<\/code>\u8fd9\u4e00\u7279\u6027\u3002<\/p>\n

\u6211\u4eec\u5c31\u4e3b\u8981\u6765\u770b\u770b\u5b83\u662f\u600e\u4e48\u6765\u8868\u793a\u7ee7\u627f\u7684\u5427\uff01<\/p>\n

pragma solidity ^0.4.16; contract Father{ uint money = 10000; function noSmoking() public returns(string){ return \"I'm not somking\"; } } contract Son is Father{ function getMoney() returns(uint){ return money; } } <\/code><\/pre>\n

\u5173\u4e8esolidity<\/code>\u7684\u7ee7\u627f\u5f88\u7b80\u5355\uff0c\u8bed\u6cd5\u4fbf\u662f\uff1a\u513f\u5b50\u662f\u7236\u4eb2<\/code>\u3002<\/p>\n

\u6211\u4eec\u5206\u522b\u90e8\u7f72\u7236\u4eb2\u5408\u7ea6\u548c\u513f\u5b50\u5408\u7ea6\uff0c\u6267\u884c\u540e\u5219\u53ef\u5f97\u5230\u5982\u4e0b\u7ed3\u679c\uff1a<\/p>\n

\"\u667a\u80fd\u5408\u7ea6\u5408\u7ea6\u5360\u6bd4_solidity\u667a\u80fd\u5408\u7ea6<\/p>\n

\u6211\u4eec\u53ef\u4ee5\u770b\u51fa\uff0c\u6211\u7236\u4eb2\u7684\u94b1\u5c31\u662f\u6211\u7684\u94b1\u3002\uff08\u4ee5\u540e\u6709\u9057\u4ea7\u7a0e\uff0c\u53ef\u5c31\u4e0d\u80fd\u8fd9\u4e48\u8bf4\u4e86\u54c8\uff09\u3002\u6211\u7238\u7238\u4e0d\u62bd\u70df\uff0c\u6211\u7ee7\u627f\u4e86\u6211\u7238\u7238\u7684\u610f\u5fd7\uff0c\u4e5f\u4e0d\u62bd\u70df\u3002<\/p>\n

\u5173\u4e8e\u7ee7\u627f\uff0c\u5c31\u4ecb\u7ecd\u5230\u8fd9\u91cc\u54c8\u3002<\/p>\n

14\u3001\u5bf9\u8c61\u7684\u8fde\u7eed\u7ee7\u627f<\/h5>\n

\u4e3a\u4e86\u7b80\u5316\u5b66\u4e60\u6210\u672c\uff0c\u8fd9\u91cc\u4e0d\u505a\u8fc7\u591a\u63cf\u8ff0\uff0c\u6211\u4eec\u7684solidity<\/code>\u548c\u5176\u4ed6\u9ad8\u7ea7\u8bed\u8a00\u7c7b\u4f3c\uff0c\u7ee7\u627f<\/code>\u7279\u6027\u662f\u652f\u6301\u4f20\u9012\u7684\u3002<\/p>\n

\u8fd9\u91cc\u9762\u5305\u542b\u4e86\u5408\u7ea6\u7684\u5c5e\u6027\u548c\u5408\u7ea6\u7684\u884c\u4e3a\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u6211\u7237\u7237\u7684\u662f\u6211\u7238\u7238\u7684\uff0c\u4e5f\u662f\u6211\u7684\u3002<\/p>\n

15\u3001\u9057\u4f20\u7279\u6027\u2013\u7ee7\u627f\u4e2d\u7684\u6743\u9650<\/h5>\n

\u6211\u4eec\u5e94\u8be5\u90fd\u5b66\u8fc7\uff0c\u9c81\u8fc5\u5148\u751f\u7684\u300a\u62ff\u6765\u4e3b\u4e49\u300b\u8fd9\u7bc7\u6587\u7ae0\u5427\uff0c\u5bf9\u4e8e\u7ee7\u627f<\/code>\uff0c\u6211\u4eec\u4e5f\u5e94\u5f53\u6709\u8fd9\u79cd\u4e0d\u80fd\u5168\u76d8\u5426\u5b9a\uff0c\u4e5f\u4e0d\u80fd\u7167\u5355\u5168\u6536\u7684\u60f3\u6cd5\uff0c\u90a3\u4e48\u600e\u4e48\u505a\u5230\u6709\u7684\u653e\u77e2\u5462\uff1f\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u6743\u9650\u6765\u63a7\u5236\u3002<\/p>\n

\u7238\u7238\u7684\u4f18\u70b9\uff0c\u6211\u4eec\u8981\u7ee7\u627f\uff0c\u7238\u7238\u7684\u6076\u4e60\uff0c\u6211\u4eec\u5f53\u7136\u8981\u62d2\u7edd\u3002<\/p>\n

pragma solidity ^0.4.16;<\/span> contract Father{ \n   <\/span> \/\/ \u7238\u7238\u7684\u79c1\u623f\u94b1 \u4e0d\u53ef\u4ee5\u88ab\u7ee7\u627f uint private privateMoney =<\/span> 2000;<\/span> \/\/ \u53ef\u4ee5\u88ab\u7ee7\u627f \/\/ uint privateMoney =<\/span> 2000;<\/span> \/\/ uint public privateMoney =<\/span> 2000;<\/span> \/\/ uint internal privateMoney =<\/span> 2000;<\/span> \/\/ external \u4e0d\u80fd\u4fee\u9970\u5c5e\u6027 \/\/ uint external privateMoney =<\/span> 2000;<\/span> uint money =<\/span> 10000;<\/span> function<\/span> noSmoking(<\/span>)<\/span> view returns(<\/span>string)<\/span>{ \n   <\/span> return<\/span> \"I'm not somking\"<\/span>;<\/span> }<\/span> }<\/span> contract Son is Father{ \n   <\/span> function<\/span> getMoney(<\/span>)<\/span> view returns(<\/span>uint)<\/span>{ \n   <\/span> return<\/span> money;<\/span> }<\/span> \/\/ \u7238\u7238\u7684\u79c1\u623f\u94b1 \u6211\u4eec\u6ca1\u6709\u529e\u6cd5\u7ee7\u627f \u76f4\u63a5\u7f16\u8bd1\u62a5\u9519 function<\/span> getPrivateMoney(<\/span>)<\/span> view returns(<\/span>uint)<\/span>{ \n   <\/span> return<\/span> privateMoney;<\/span> }<\/span> }<\/span> <\/code><\/pre>\n

\u4e0a\u8ff0\u7684\u6848\u4f8b\uff0c\u6211\u4eec\u53ef\u4ee5\u770b\u5230\uff0c\u5b50\u5408\u7ea6\u662f\u6ca1\u6709\u529e\u6cd5\u7ee7\u627f\u7236\u5408\u7ea6\u7684\u79c1\u6709\u5c5e\u6027\u53d8\u91cf\u7684\u3002\u8fd9\u91cc\u6211\u4eec\u7528\u5230\u4e86\u4fee\u9970\u7b26private<\/code>\u8868\u793a\u79c1\u6709\u7684\u3002\u8fd9\u91cc\u6211\u4eec\u628a\u5173\u4e8e\u7ee7\u627f\u7279\u6027\u7684\u4fee\u9970\u7b26\u505a\u4e00\u4e2a\u603b\u7ed3.<\/p>\n

    \n
  • \u5982\u679c\u5c5e\u6027\u4e0d\u52a0\u4e0a\u4efb\u4f55\u4fee\u9970\u7b26\uff0c\u662f\u53ef\u4ee5\u88ab\u7ee7\u627f\u7684\u3002<\/li>\n
  • \u5982\u679c\u4f7f\u7528public\u4fee\u9970\u6210\u5458\u5c5e\u6027\uff0c\u662f\u53ef\u4ee5\u88ab\u7ee7\u627f\u7684<\/li>\n
  • \u5982\u679c\u4f7f\u7528internal\u4fee\u9970\u6210\u5458\u5c5e\u6027\uff0c\u662f\u53ef\u4ee5\u88ab\u7ee7\u627f\u7684<\/li>\n
  • external \u4e0d\u652f\u6301\u4fee\u590d\u6210\u5458\u5c5e\u6027<\/li>\n
  • \u5982\u679c\u4f7f\u7528private \u4fee\u9970\u6210\u5458\u5c5e\u6027\uff0c\u662f\u4e0d\u80fd\u591f\u88ab\u7ee7\u627f\u7684\u3002<\/li>\n<\/ul>\n

    \u4e0a\u9762\u6211\u4eec\u4ecb\u7ecd\u4e86\u5408\u7ea6\u5c5e\u6027\u7684\u7ee7\u627f\u4e2d\u6743\u9650\uff0c\u63a5\u4e0b\u6765\u6211\u4eec\u770b\u770b\u51fd\u6570\u4e2d\u7ee7\u627f\u7684\u6743\u9650\u95ee\u9898\u5427\u3002<\/p>\n

    public\u4fee\u9970\u7236\u5408\u7ea6\u51fd\u6570<\/h6>\n

    \u5b50\u5408\u7ea6\u53ef\u4ee5\u6b63\u5e38\u8c03\u7528\u7236\u5408\u7ea6\u7684\u51fd\u6570\u3002<\/p>\n

    pragma solidity ^0.4.16; contract Father{ function noSmoking() public view returns(string){ return \"I'm not somking\"; } } contract Son is Father{ function test() public view returns(string){ return noSmoking(); } } <\/code><\/pre>\n
    private\u4fee\u9970\u7236\u5408\u7ea6\u51fd\u6570<\/h6>\n

    \u7f16\u8bd1\u4e0d\u901a\u8fc7\u3002<\/p>\n

    pragma solidity ^0.4.16;<\/span> contract Father{ \n   <\/span> function<\/span> noSmoking(<\/span>)<\/span> private view returns(<\/span>string)<\/span>{ \n   <\/span> return<\/span> \"I'm not somking\"<\/span>;<\/span> }<\/span> }<\/span> contract Son is Father{ \n   <\/span> function<\/span> test(<\/span>)<\/span> public view returns(<\/span>string)<\/span>{ \n   <\/span> return<\/span> noSmoking(<\/span>)<\/span>;<\/span> }<\/span> }<\/span> <\/code><\/pre>\n
    internal\u4fee\u9970\u7236\u5408\u7ea6\u51fd\u6570<\/h6>\n

    \u7236\u51fd\u6570\u4e0d\u53ef\u89c1\uff0c\u5b50\u5408\u7ea6\u53ef\u4ee5\u8c03\u7528<\/p>\n

    pragma solidity ^0.4.16;<\/span> contract Father{ \n   <\/span> function<\/span> noSmoking(<\/span>)<\/span> internal pure returns(<\/span>string)<\/span>{ \n   <\/span> return<\/span> \"I'm not somking\"<\/span>;<\/span> }<\/span> }<\/span> contract Son is Father{ \n   <\/span> function<\/span> test(<\/span>)<\/span> public pure returns(<\/span>string)<\/span>{ \n   <\/span> return<\/span> noSmoking(<\/span>)<\/span>;<\/span> }<\/span> }<\/span> <\/code><\/pre>\n
    external\u4fee\u9970\u7236\u5408\u7ea6\u51fd\u6570<\/h6>\n

    \u7f16\u8bd1\u62a5\u9519\u3002<\/p>\n

    pragma solidity ^0.4.16;<\/span> contract Father{ \n   <\/span> function<\/span> noSmoking(<\/span>)<\/span> external pure returns(<\/span>string)<\/span>{ \n   <\/span> return<\/span> \"I'm not somking\"<\/span>;<\/span> }<\/span> }<\/span> contract Son is Father{ \n   <\/span> function<\/span> test(<\/span>)<\/span> public pure returns(<\/span>string)<\/span>{ \n   <\/span> return<\/span> this.noSmoking(<\/span>)<\/span>;<\/span> }<\/span> }<\/span> <\/code><\/pre>\n

    \u5173\u4e8e\u7ee7\u627f\u4e2d\u7684\u6743\u9650\uff0c\u5185\u5bb9\u4e5f\u76f8\u5bf9\u7b80\u5355\uff0c\u5927\u5bb6\u5728\u5e73\u65f6\u4f7f\u7528\u65f6\uff0c\u5176\u5b9e\u53ea\u9700\u8981\u7528 public<\/code>\u548cprivate<\/code>\u5c31\u53ef\u4ee5\u6ee1\u8db3\u5927\u90e8\u5206\u9700\u6c42\u4e86\u3002<\/p>\n

    \u9762\u5411\u533a\u5757\u94fe\u7f16\u7a0b\uff0c\u6784\u5efa\u53ef\u4fe1\u793e\u4f1a\u3002\u6211\u4eec\u4e0b\u8282\u518d\u89c1\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u667a\u80fd\u5408\u7ea6\u5408\u7ea6\u5360\u6bd4_solidity\u667a\u80fd\u5408\u7ea6\u5927\u5bb6\u597d\uff0c\u8fd9\u91cc\u662f\u901a\u5b66\u6280\u672f\uff0c\u6b22\u8fce\u5927\u5bb6\u7ee7\u7eed\u8ddf\u6211\u4e00\u8d77\u5b66\u4e60\u667a\u80fd\u5408\u7ea6\u7cfb\u5217","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/8421"}],"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=8421"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/8421\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=8421"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=8421"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=8421"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}