{"id":313827,"date":"2024-05-20T23:15:57","date_gmt":"2024-05-20T15:15:57","guid":{"rendered":""},"modified":"2024-05-20T23:16:16","modified_gmt":"2024-05-20T15:16:16","slug":"java-%e5%87%bd%e6%95%b0%e5%9f%ba%e7%a1%80%e7%9f%a5%e8%af%86%e6%9c%89%e5%93%aa%e4%ba%9b","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/313827.html","title":{"rendered":"java \u51fd\u6570\u57fa\u7840\u77e5\u8bc6\u6709\u54ea\u4e9b"},"content":{"rendered":"<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/27033253\/aa9d0b4a-f506-4277-b1d7-555d3c9c5151.webp\" alt=\"java \u51fd\u6570\u57fa\u7840\u77e5\u8bc6\u6709\u54ea\u4e9b\" \/><\/p>\n<p><p>\u51fd\u6570\u662fJava\u4e2d\u6267\u884c\u7279\u5b9a\u4efb\u52a1\u7684\u4ee3\u7801\u5757\uff0c\u5176\u57fa\u7840\u77e5\u8bc6\u5305\u62ec\u51fd\u6570\u7684\u5b9a\u4e49\u3001\u8c03\u7528\u3001\u53c2\u6570\u4f20\u9012\u3001\u8fd4\u56de\u7c7b\u578b\u548c\u4fee\u9970\u7b26\u3002<strong>\u51fd\u6570\u5b9a\u4e49<\/strong>\u9700\u8981\u5305\u62ec\u8bbf\u95ee\u4fee\u9970\u7b26\uff08public\u3001private\u7b49\uff09\u3001\u8fd4\u56de\u7c7b\u578b\u3001\u51fd\u6570\u540d\u79f0\u4ee5\u53ca\u53c2\u6570\u5217\u8868\uff0c\u53c2\u6570\u5217\u8868\u4e2d\u7684\u6bcf\u4e2a\u53c2\u6570\u7531\u53c2\u6570\u7c7b\u578b\u548c\u53c2\u6570\u540d\u7ec4\u6210\u3002<strong>\u8c03\u7528\u51fd\u6570<\/strong>\u65f6\uff0c\u9700\u8981\u6309\u7167\u5b9a\u4e49\u65f6\u6307\u5b9a\u7684\u53c2\u6570\u5217\u8868\u63d0\u4f9b\u76f8\u5e94\u7684\u53c2\u6570\u503c\u3002<strong>\u53c2\u6570\u4f20\u9012<\/strong>\u65e2\u53ef\u4ee5\u662f\u503c\u4f20\u9012\uff0c\u4e5f\u53ef\u4ee5\u662f\u5f15\u7528\u4f20\u9012\uff0c\u8fd9\u53d6\u51b3\u4e8e\u4f20\u9012\u7684\u6570\u636e\u7c7b\u578b\u3002<strong>\u8fd4\u56de\u7c7b\u578b<\/strong>\u5219\u89c4\u5b9a\u4e86\u51fd\u6570\u6267\u884c\u540e\u8fd4\u56de\u7ed9\u8c03\u7528\u8005\u7684\u6570\u636e\u7c7b\u578b\uff0c\u5982\u679c\u51fd\u6570\u4e0d\u9700\u8981\u8fd4\u56de\u503c\uff0c\u5219\u4f7f\u7528void\u4f5c\u4e3a\u8fd4\u56de\u7c7b\u578b\u3002\u6700\u540e\uff0c\u51fd\u6570\u53ef\u4ee5\u4f7f\u7528\u4e0d\u540c\u7684<strong>\u4fee\u9970\u7b26<\/strong>\u6765\u63a7\u5236\u51fd\u6570\u7684\u8bbf\u95ee\u7ea7\u522b\u548c\u5176\u4ed6\u884c\u4e3a\u5c5e\u6027\u3002<\/p>\n<\/p>\n<p><p>\u51fd\u6570\u57fa\u7840\u77e5\u8bc6\u7684\u8be6\u7ec6\u63cf\u8ff0\u91cd\u70b9\u653e\u5728<strong>\u51fd\u6570\u7684\u5b9a\u4e49<\/strong>\u4e0a\u3002\u5728Java\u4e2d\uff0c\u4e00\u4e2a\u5178\u578b\u7684\u51fd\u6570\u5b9a\u4e49\u5305\u62ec\u51e0\u4e2a\u6838\u5fc3\u7ec4\u6210\u90e8\u5206\u3002\u9996\u5148\u662f\u8bbf\u95ee\u4fee\u9970\u7b26\uff0c\u5b83\u51b3\u5b9a\u4e86\u54ea\u4e9b\u5176\u4ed6\u7c7b\u53ef\u4ee5\u4f7f\u7528\u8fd9\u4e2a\u51fd\u6570\u3002\u5176\u6b21\u662f\u8fd4\u56de\u7c7b\u578b\uff0c\u6bcf\u4e2a\u51fd\u6570\u90fd\u9700\u8981\u58f0\u660e\u5b83\u8fd4\u56de\u7684\u6570\u636e\u7c7b\u578b\u3002\u65e0\u8fd4\u56de\u503c\u7684\u51fd\u6570\u4f7f\u7528void\u5173\u952e\u5b57\u3002\u7136\u540e\u662f\u51fd\u6570\u540d\uff0c\u5b83\u5e94\u5f53\u6e05\u6670\u5730\u8868\u660e\u51fd\u6570\u7684\u7528\u9014\u3002\u51fd\u6570\u540d\u540e\u9762\u8ddf\u7740\u62ec\u53f7\u548c\u53c2\u6570\u5217\u8868\uff0c\u8fd9\u91cc\u6307\u5b9a\u4e86\u8c03\u7528\u51fd\u6570\u65f6\u9700\u8981\u63d0\u4f9b\u7684\u4fe1\u606f\u3002\u6700\u540e\u53ef\u80fd\u8fd8\u5305\u62ec\u4e00\u7ec4\u5f02\u5e38\u58f0\u660e\uff0c\u8fd9\u8868\u793a\u51fd\u6570\u5728\u6267\u884c\u65f6\u53ef\u80fd\u4f1a\u629b\u51fa\u8fd9\u4e9b\u5f02\u5e38\u3002<\/p>\n<\/p>\n<p><p>\u73b0\u5728\uff0c\u8ba9\u6211\u4eec\u8fdb\u4e00\u6b65\u6df1\u5165\u5230\u6bcf\u4e2a\u90e8\u5206\u7684\u5177\u4f53\u5185\u5bb9\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u51fd\u6570\u7684\u5b9a\u4e49\u4e0e\u58f0\u660e<\/h3>\n<\/p>\n<p><p>\u51fd\u6570\u5b9a\u4e49\u5728Java\u4e2d\u8d77\u7740\u6838\u5fc3\u7684\u4f5c\u7528\uff0c\u5b9a\u4e49\u4e00\u4e2a\u51fd\u6570\u9700\u8981\u9075\u5b88\u4e00\u5b9a\u7684\u8bed\u6cd5\u89c4\u5219\uff0c\u540c\u65f6\u4e5f\u4f53\u73b0\u4e86\u51fd\u6570\u7f16\u7a0b\u7684\u51e0\u4e2a\u5173\u952e\u6982\u5ff5\u3002\u5728\u51fd\u6570\u5b9a\u4e49\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u9700\u8981\u6307\u5b9a\u4e00\u4e2a<strong>\u8bbf\u95ee\u4fee\u9970\u7b26<\/strong>\uff0c\u8fd9\u51b3\u5b9a\u4e86\u5176\u4ed6\u7c7b\u662f\u5426\u53ef\u4ee5\u8bbf\u95ee\u6b64\u51fd\u6570\u3002\u63a5\u7740\u662f<strong>\u8fd4\u56de\u7c7b\u578b<\/strong>\uff0c\u5b83\u8868\u660e\u51fd\u6570\u5b8c\u6210\u4efb\u52a1\u540e\u80fd\u8fd4\u56de\u4ec0\u4e48\u7c7b\u578b\u7684\u6570\u636e\u3002<\/p>\n<\/p>\n<p><h4>\u51fd\u6570\u7684\u8bbf\u95ee\u4fee\u9970\u7b26<\/h4>\n<\/p>\n<p><p>\u8bbf\u95ee\u4fee\u9970\u7b26\u4e3b\u8981\u6709\u56db\u79cd\uff1a<code>public<\/code>\u3001<code>protected<\/code>\u3001<code>default<\/code>\uff08\u65e0\u4fee\u9970\u7b26\uff09\u548c<code>private<\/code>\u3002<code>public<\/code>\u51fd\u6570\u5bf9\u6240\u6709\u7c7b\u53ef\u89c1\uff0c\u800c<code>private<\/code>\u53ea\u80fd\u88ab\u672c\u7c7b\u8bbf\u95ee\u3002<\/p>\n<\/p>\n<p><h4>\u51fd\u6570\u7684\u8fd4\u56de\u7c7b\u578b<\/h4>\n<\/p>\n<p><p>\u8fd4\u56de\u7c7b\u578b\u662f\u5fc5\u9700\u7684\uff0c\u5e76\u4e14\u5fc5\u987b\u5728\u5b9a\u4e49\u51fd\u6570\u65f6\u6307\u5b9a\u3002\u5b83\u53ef\u4ee5\u662f\u4efb\u4f55\u6570\u636e\u7c7b\u578b\uff0c\u5305\u62ec\u57fa\u672c\u7c7b\u578b\uff08\u5982int\u3001double\u7b49\uff09\u548c\u5f15\u7528\u7c7b\u578b\uff08\u5982String\u3001\u6570\u7ec4\u6216\u4efb\u4f55\u5bf9\u8c61\uff09\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u51fd\u6570\u7684\u53c2\u6570\u4e0e\u91cd\u8f7d<\/h3>\n<\/p>\n<p><p>\u5728\u51fd\u6570\u4e2d\uff0c\u6211\u4eec\u901a\u5e38\u9700\u8981\u63d0\u4f9b<strong>\u53c2\u6570<\/strong>\uff08\u4e5f\u79f0\u4e3a\u5f62\u5f0f\u53c2\u6570\uff09\uff0c\u8fd9\u4e9b\u53c2\u6570\u7528\u4e8e\u5c06\u503c\u4f20\u9012\u5230\u51fd\u6570\u5185\u90e8\u3002\u53e6\u4e00\u4e2a\u4e0e\u53c2\u6570\u76f8\u5173\u7684\u6982\u5ff5\u662f<strong>\u51fd\u6570\u91cd\u8f7d<\/strong>\uff0c\u5b83\u5141\u8bb8\u540c\u4e00\u4e2a\u7c7b\u4e2d\u5b58\u5728\u591a\u4e2a\u540c\u540d\u51fd\u6570\uff0c\u53ea\u8981\u5b83\u4eec\u7684\u53c2\u6570\u5217\u8868\u4e0d\u540c\u3002<\/p>\n<\/p>\n<p><h4>\u53c2\u6570\u4f20\u9012<\/h4>\n<\/p>\n<p><p>\u53c2\u6570\u53ef\u4ee5\u662f\u57fa\u672c\u6570\u636e\u7c7b\u578b\uff08\u503c\u4f20\u9012\uff09\u6216\u5f15\u7528\u7c7b\u578b\uff08\u5f15\u7528\u4f20\u9012\uff09\u3002<strong>\u503c\u4f20\u9012<\/strong>\u610f\u5473\u7740\u8c03\u7528\u65f6\u4f20\u9012\u6570\u636e\u503c\u7684\u526f\u672c\uff0c\u800c\u5728\u51fd\u6570\u4e2d\u5bf9\u53c2\u6570\u7684\u4fee\u6539\u4e0d\u4f1a\u5f71\u54cd\u539f\u59cb\u6570\u636e\u3002<strong>\u5f15\u7528\u4f20\u9012<\/strong>\u610f\u5473\u7740\u4f20\u9012\u7684\u662f\u5bf9\u8c61\u5f15\u7528\u7684\u526f\u672c\uff0c\u51fd\u6570\u4e2d\u5bf9\u5bf9\u8c61\u7684\u4fee\u6539\u4f1a\u5f71\u54cd\u5230\u539f\u59cb\u5bf9\u8c61\u3002<\/p>\n<\/p>\n<p><h4>\u51fd\u6570\u91cd\u8f7d<\/h4>\n<\/p>\n<p><p>\u51fd\u6570\u91cd\u8f7d\u901a\u8fc7\u5141\u8bb8\u540c\u540d\u51fd\u6570\u5b58\u5728\uff0c\u4f7f\u5f97\u51fd\u6570\u8c03\u7528\u66f4\u52a0\u7075\u6d3b\u3002\u91cd\u8f7d\u51fd\u6570\u5fc5\u987b\u6709\u4e0d\u540c\u7684\u53c2\u6570\u5217\u8868\uff0c\u53ef\u4ee5\u662f\u4e0d\u540c\u7684\u53c2\u6570\u7c7b\u578b\u3001\u4e0d\u540c\u7684\u53c2\u6570\u6570\u91cf\u6216\u4e0d\u540c\u7684\u53c2\u6570\u987a\u5e8f\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u51fd\u6570\u7684\u8c03\u7528<\/h3>\n<\/p>\n<p><p>\u8c03\u7528\u51fd\u6570\u662f\u4f7f\u7528\u5176\u529f\u80fd\u7684\u65b9\u6cd5\u3002\u5728Java\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u521b\u5efa\u5bf9\u8c61\u5b9e\u4f8b\u8c03\u7528<strong>\u5b9e\u4f8b\u65b9\u6cd5<\/strong>\uff0c\u6216\u8005\u901a\u8fc7\u7c7b\u540d\u76f4\u63a5\u8c03\u7528<strong>\u9759\u6001\u65b9\u6cd5<\/strong>\u3002<\/p>\n<\/p>\n<p><h4>\u5b9e\u4f8b\u65b9\u6cd5<\/h4>\n<\/p>\n<p><p>\u8c03\u7528\u5b9e\u4f8b\u65b9\u6cd5\u9700\u8981\u5177\u6709\u7c7b\u7684\u5bf9\u8c61\u5b9e\u4f8b\u3002\u901a\u8fc7\u70b9\u64cd\u4f5c\u7b26\uff08<code>.<\/code>\uff09\u8fde\u63a5\u5bf9\u8c61\u53d8\u91cf\u548c\u51fd\u6570\u540d\u6765\u8fdb\u884c\u8c03\u7528\u3002<\/p>\n<\/p>\n<p><h4>\u9759\u6001\u65b9\u6cd5<\/h4>\n<\/p>\n<p><p>\u9759\u6001\u65b9\u6cd5\u5c5e\u4e8e\u7c7b\u800c\u4e0d\u662f\u5bf9\u8c61\u5b9e\u4f8b\u3002\u56e0\u6b64\uff0c\u5b83\u4eec\u53ef\u4ee5\u5728\u6ca1\u6709\u5bf9\u8c61\u5b9e\u4f8b\u7684\u60c5\u51b5\u4e0b\u8c03\u7528\u3002\u901a\u5e38\u4f7f\u7528\u7c7b\u540d\u76f4\u63a5\u8fdb\u884c\u9759\u6001\u65b9\u6cd5\u7684\u8c03\u7528\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u51fd\u6570\u7684\u9012\u5f52<\/h3>\n<\/p>\n<p><p>\u9012\u5f52\u662f\u51fd\u6570\u7f16\u7a0b\u4e2d\u7684\u4e00\u79cd\u6280\u5de7\uff0c\u5176\u4e2d\u51fd\u6570\u76f4\u63a5\u6216\u95f4\u63a5\u5730\u8c03\u7528\u81ea\u8eab\u3002\u9012\u5f52\u53ef\u4ee5\u7528\u6765\u89e3\u51b3\u5206\u800c\u6cbb\u4e4b\u7684\u95ee\u9898\uff0c\u5982\u6392\u5e8f\u7b97\u6cd5\u6216\u6811\u7ed3\u6784\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<p><h4>\u9012\u5f52\u7684\u539f\u7406<\/h4>\n<\/p>\n<p><p>\u5728\u9012\u5f52\u4e2d\uff0c\u91cd\u8981\u7684\u662f\u5728\u6bcf\u6b21\u51fd\u6570\u8c03\u7528\u65f6\u90fd\u6709\u4e00\u4e2a\u57fa\u672c\u60c5\u51b5\uff08\u7ec8\u6b62\u6761\u4ef6\uff09\uff0c\u4ee5\u9632\u6b62\u65e0\u9650\u9012\u5f52\u3002<\/p>\n<\/p>\n<p><h4>\u9012\u5f52\u7684\u5b9e\u73b0<\/h4>\n<\/p>\n<p><p>\u9012\u5f52\u51fd\u6570\u901a\u5e38\u6709\u4e24\u90e8\u5206\uff1a\u9012\u5f52\u8c03\u7528\u548c\u57fa\u672c\u60c5\u51b5\u3002\u5f53\u6ee1\u8db3\u67d0\u4e9b\u6761\u4ef6\u65f6\uff08\u901a\u5e38\u662f\u9012\u5f52\u6df1\u5ea6\uff09\uff0c\u51fd\u6570\u4f1a\u8fd4\u56de\u800c\u4e0d\u662f\u518d\u6b21\u8c03\u7528\u81ea\u8eab\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p><strong>Q1: \u4ec0\u4e48\u662fJava\u51fd\u6570\uff1f<\/strong><\/p>\n<p>Java\u51fd\u6570\u662f\u4e00\u6bb5\u53ef\u91cd\u590d\u8c03\u7528\u7684\u4ee3\u7801\u5757\uff0c\u5b83\u53ef\u4ee5\u6267\u884c\u7279\u5b9a\u7684\u4efb\u52a1\u5e76\u8fd4\u56de\u4e00\u4e2a\u503c\uff08\u5982\u679c\u9700\u8981\uff09\u3002\u51fd\u6570\u662fJava\u7f16\u7a0b\u4e2d\u7684\u57fa\u672c\u6784\u5efa\u5757\u4e4b\u4e00\uff0c\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u7ec4\u7ec7\u548c\u91cd\u7528\u4ee3\u7801\u3002<\/p>\n<p><strong>Q2: \u5982\u4f55\u5b9a\u4e49\u4e00\u4e2aJava\u51fd\u6570\uff1f<\/strong><\/p>\n<p>\u8981\u5b9a\u4e49\u4e00\u4e2aJava\u51fd\u6570\uff0c\u9700\u8981\u4f7f\u7528\u5173\u952e\u5b57 &quot;public&quot; \u6216 &quot;private&quot; \u6765\u6307\u5b9a\u8bbf\u95ee\u6743\u9650\u4fee\u9970\u7b26\uff0c\u7136\u540e\u6307\u5b9a\u8fd4\u56de\u7c7b\u578b\uff08\u5982\u679c\u9700\u8981\u8fd4\u56de\u503c\uff09\uff0c\u63a5\u7740\u662f\u51fd\u6570\u7684\u540d\u79f0\uff0c\u7136\u540e\u662f\u62ec\u53f7\u5185\u7684\u53c2\u6570\u5217\u8868\uff0c\u6700\u540e\u662f\u51fd\u6570\u4f53\u5757\u5185\u7684\u4ee3\u7801\u903b\u8f91\u3002<\/p>\n<p><strong>Q3: Java\u51fd\u6570\u4e2d\u7684\u53c2\u6570\u6709\u54ea\u4e9b\u7c7b\u578b\uff1f<\/strong><\/p>\n<p>Java\u51fd\u6570\u7684\u53c2\u6570\u53ef\u4ee5\u662f\u57fa\u672c\u6570\u636e\u7c7b\u578b\uff08\u5982\u6574\u6570\u3001\u6d6e\u70b9\u6570\u3001\u5e03\u5c14\u503c\u7b49\uff09\uff0c\u4e5f\u53ef\u4ee5\u662f\u5f15\u7528\u7c7b\u578b\uff08\u5982\u5b57\u7b26\u4e32\u3001\u6570\u7ec4\u3001\u7c7b\u5bf9\u8c61\u7b49\uff09\u3002\u6b64\u5916\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528\u53ef\u53d8\u6570\u91cf\u7684\u53c2\u6570\uff08varargs\uff09\u6765\u63a5\u53d7\u4e0d\u786e\u5b9a\u6570\u91cf\u7684\u53c2\u6570\u3002\u5728\u51fd\u6570\u5185\u90e8\uff0c\u53ef\u4ee5\u4f7f\u7528\u8fd9\u4e9b\u53c2\u6570\u8fdb\u884c\u8ba1\u7b97\u3001\u64cd\u4f5c\u7b49\u5904\u7406\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u51fd\u6570\u662fJava\u4e2d\u6267\u884c\u7279\u5b9a\u4efb\u52a1\u7684\u4ee3\u7801\u5757\uff0c\u5176\u57fa\u7840\u77e5\u8bc6\u5305\u62ec\u51fd\u6570\u7684\u5b9a\u4e49\u3001\u8c03\u7528\u3001\u53c2\u6570\u4f20\u9012\u3001\u8fd4\u56de\u7c7b\u578b\u548c\u4fee\u9970\u7b26\u3002\u51fd\u6570\u5b9a\u4e49\u9700\u8981 [&hellip;]","protected":false},"author":3,"featured_media":313850,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/313827"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=313827"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/313827\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/313850"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=313827"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=313827"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=313827"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}