{"id":76,"date":"2015-03-30T10:55:22","date_gmt":"2015-03-30T02:55:22","guid":{"rendered":"https:\/\/ai.zhousir.top\/?p=76"},"modified":"2026-08-18T12:09:24","modified_gmt":"2026-08-18T04:09:24","slug":"java%e5%8f%98%e9%87%8f%e7%9a%84%e4%bd%9c%e7%94%a8%e5%9f%9f","status":"publish","type":"post","link":"https:\/\/ai.zhousir.top\/?p=76","title":{"rendered":"Java\u53d8\u91cf\u7684\u4f5c\u7528\u57df"},"content":{"rendered":"<section id=\"wenyan\" style=\"font-family: system-ui, 'Apple Color Emoji', 'Segoe UI', 'Segoe UI Symbol', 'Noto Sans', Roboto, sans-serif; line-height: 1.75; font-size: 16px; color: #000000; caret-color: #000000;\" data-provider=\"WenYan\">\n<p style=\"margin: 1em 0px;\">Java \u91cc\u53d8\u91cf\u7684\u4f5c\u7528\u57df\u53ef\u4ee5\u5206\u6210\u56db\u7ea7\uff1a<strong style=\"color: #4870ac;\">\u7c7b\u7ea7<\/strong>\u3001<strong style=\"color: #4870ac;\">\u5bf9\u8c61\u5b9e\u4f8b\u7ea7<\/strong>\u3001<strong style=\"color: #4870ac;\">\u65b9\u6cd5\u7ea7<\/strong>\u3001<strong style=\"color: #4870ac;\">\u5757\u7ea7<\/strong>\u3002\u80fd\u770b\u89c1\u8c01\u3001\u6d3b\u591a\u4e45\uff0c\u5168\u7531\u5b9a\u4e49\u4f4d\u7f6e\u51b3\u5b9a\u3002<\/p>\n<p style=\"margin: 1em 0px;\">\u7c7b\u7ea7\u53d8\u91cf\u7528 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">static<\/code> \u4fee\u9970\uff0c\u6709\u65f6\u88ab\u4fd7\u79f0\u4e3a\u300c\u5168\u5c40\u53d8\u91cf\u300d\u2014\u2014\u5176\u5b9e\u5b83\u5c5e\u4e8e\u7c7b\uff0c\u4e0d\u53eb\u771f\u6b63\u7684\u5168\u5c40\u3002\u7c7b\u52a0\u8f7d\u540e\u5c31\u5360\u5185\u5b58\uff0c\u7528\u7c7b\u540d\u5c31\u80fd\u8bbf\u95ee\uff0c\u4e0d\u5fc5\u5148 new\u3002\u5bf9\u8c61\u5b9e\u4f8b\u7ea7\u5c31\u662f\u6210\u5458\u53d8\u91cf\uff0c\u5fc5\u987b\u5148\u5b9e\u4f8b\u5316\u624d\u5206\u914d\u3001\u624d\u80fd\u7528\u3002<\/p>\n<p><!--more--><\/p>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u4e00\u3001\u56db\u7ea7\u4f5c\u7528\u57df<\/h2>\n<p style=\"margin: 1em 0px;\">\u65b9\u6cd5\u7ea7\u53d8\u91cf\u5c31\u662f\u65b9\u6cd5\u5185\u90e8\u7684\u5c40\u90e8\u53d8\u91cf\u3002\u5757\u7ea7\u53d8\u91cf\u5b9a\u4e49\u5728\u4e00\u5bf9\u5927\u62ec\u53f7\u91cc\uff0c\u5757\u7ed3\u675f\u5c31\u6d88\u5931\uff0c\u4f8b\u5982 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">if<\/code>\u3001<code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">for<\/code> \u7684\u82b1\u62ec\u53f7\u3002<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">{\n    int age = 3;\n    String name = \"www.weixueyuan.net\";\n    \/\/ \u6b63\u786e\uff1a\u5757\u5185\u90e8\u53ef\u4ee5\u8bbf\u95ee age \u548c name\n    System.out.println(name + \"\u5df2\u7ecf\" + age + \"\u5c81\u4e86\");\n}\n\/\/ \u9519\u8bef\uff1a\u5757\u5916\u90e8\u65e0\u6cd5\u8bbf\u95ee age \u548c name\nSystem.out.println(name + \"\u5df2\u7ecf\" + age + \"\u5c81\u4e86\");<\/code><\/pre>\n<table style=\"display: table; text-align: left; overflow: auto; border-collapse: collapse; margin: 1.4em auto; max-width: 100%; table-layout: fixed; overflow-wrap: break-word; word-break: break-all;\" width=\"800\">\n<thead>\n<tr>\n<th style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top; text-align: center; font-weight: bold; color: #4870ac; background: #f7f7f7;\">\u7ea7\u522b<\/th>\n<th style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top; text-align: center; font-weight: bold; color: #4870ac; background: #f7f7f7;\">\u600e\u4e48\u58f0\u660e<\/th>\n<th style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top; text-align: center; font-weight: bold; color: #4870ac; background: #f7f7f7;\">\u8c01\u80fd\u770b\u89c1<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u7c7b\u7ea7<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">static \u5b57\u6bb5<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u7c7b\u540d\u6216\u4efb\u610f\u5b9e\u4f8b\uff1b\u65b9\u6cd5\u3001\u5757\u90fd\u80fd\u8bfb<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u5b9e\u4f8b\u7ea7<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u975e static \u5b57\u6bb5<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u5148 new\uff1b\u5b9e\u4f8b\u65b9\u6cd5\u3001\u5757\u90fd\u80fd\u8bfb<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u65b9\u6cd5\u7ea7<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u65b9\u6cd5\u5185\u5c40\u90e8\u53d8\u91cf<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u672c\u65b9\u6cd5\u53ca\u5176\u4e2d\u7684\u5757\uff1b\u5fc5\u987b\u663e\u5f0f\u521d\u59cb\u5316<\/td>\n<\/tr>\n<tr>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u5757\u7ea7<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">{ }\u3001if\u3001for \u5185<\/td>\n<td style=\"border: 1px solid #d9dfe4; padding: 9px 12px; font-size: 0.75em; line-height: 22px; vertical-align: top;\">\u4ec5\u5757\u5185\uff1b\u5fc5\u987b\u663e\u5f0f\u521d\u59cb\u5316<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<ul style=\"padding-left: 1rem; margin-left: 1rem; font-size: 0.9rem; list-style-type: disc;\">\n<li>\n<section>\u65b9\u6cd5\u5185\u90e8\u9664\u4e86\u65b9\u6cd5\u7ea7\u53d8\u91cf\uff0c\u8fd8\u80fd\u8bbf\u95ee\u7c7b\u7ea7\u548c\u5b9e\u4f8b\u7ea7\u53d8\u91cf\u3002<\/section>\n<\/li>\n<li>\n<section>\u5757\u5185\u90e8\u80fd\u8bbf\u95ee\u7c7b\u7ea7\u3001\u5b9e\u4f8b\u7ea7\uff1b\u82e5\u5757\u5728\u65b9\u6cd5\u91cc\uff0c\u8fd8\u80fd\u8bbf\u95ee\u8be5\u65b9\u6cd5\u7684\u5c40\u90e8\u53d8\u91cf\u3002<\/section>\n<\/li>\n<li>\n<section>\u65b9\u6cd5\u7ea7\u548c\u5757\u7ea7\u5fc5\u987b<strong style=\"color: #4870ac;\">\u663e\u5f0f\u521d\u59cb\u5316<\/strong>\u624d\u80fd\u4f7f\u7528\uff08\u539f\u6587\u5199\u6210\u300c\u663e\u793a\u300d\uff0c\u5e94\u4e3a\u300c\u663e\u5f0f\u300d\uff09\u3002\u5b9e\u4f8b\u5b57\u6bb5\u53ef\u4ee5\u4e0d\u5199\u521d\u503c\uff0c\u4f1a\u6709\u9ed8\u8ba4\u503c\uff0c\u4f8b\u5982 int \u4e3a 0\u3002<\/section>\n<\/li>\n<\/ul>\n<h2 style=\"padding: 1px 12.5px; color: #ffffff; margin: 1.2em 0px 1em; border-radius: 4px; display: inline-block; background-color: #4870ac; font-size: 1.3em;\">\u4e8c\u3001\u6f14\u793a\u4ee3\u7801<\/h2>\n<p style=\"margin: 1em 0px;\">\u7c7b\u521d\u59cb\u5316\u65f6\u4f1a\u8dd1\u4e00\u904d\u5b9e\u4f8b\u521d\u59cb\u5316\u5757\u3002\u4e0b\u9762\u7684 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">j = 2<\/code> \u53ea\u6d3b\u5728\u90a3\u4e2a\u5757\u91cc\uff0c<code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">test1()<\/code> \u91cc\u7684 <code style=\"font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; color: #4870ac; font-size: 0.9em; font-weight: normal; overflow-wrap: break-word; padding: 2px 4px; border-radius: 3px; margin: 2px; background-color: #f6f8fa; word-break: break-all;\">j<\/code> \u662f\u53e6\u4e00\u4e2a\u5c40\u90e8\u53d8\u91cf\u3002<\/p>\n<pre style=\"overflow: auto hidden; word-break: normal; white-space: pre; tab-size: 2; border-radius: 5px; line-height: 2; margin: 1em 0.5em; padding: 0.5em; box-shadow: rgba(0, 0, 0, 0.55) 0px 1px 5px; font-size: 12px; background: #002b36; max-width: 100%; overflow-wrap: normal;\"><code class=\"hljs\" style=\"word-break: normal; white-space: nowrap; tab-size: 2; font-size: 12px; font-family: Menlo, Monaco, Consolas, 'Liberation Mono', 'Roboto Mono', 'Courier New', 'Microsoft YaHei', monospace; display: block; overflow-x: auto; margin: 0.5em; padding: 3px 5px; color: #93a1a1; background: #002b36; overflow-wrap: normal;\">public class Demo {\n    public static String name = \"\u65b0\u534e\u82d1\";  \/\/ \u7c7b\u7ea7\u53d8\u91cf\n    public int i; \/\/ \u5b9e\u4f8b\u7ea7\u53d8\u91cf\uff0c\u9ed8\u8ba4 0\n\n    {\n        int j = 2; \/\/ \u5757\u7ea7\u53d8\u91cf\uff0c\u51fa\u4e86\u8fd9\u4e2a\u521d\u59cb\u5316\u5757\u5c31\u4e0d\u80fd\u7528\n    }\n\n    public void test1() {\n        int j = 3;  \/\/ \u65b9\u6cd5\u7ea7\u53d8\u91cf\n        if (j == 3) {\n            int k = 5;  \/\/ \u5757\u7ea7\u53d8\u91cf\uff0cif \u5916\u9762\u4e0d\u80fd\u8bbf\u95ee\n        }\n        System.out.println(\"name=\" + name + \", i=\" + i + \", j=\" + j);\n    }\n\n    public static void main(String[] args) {\n        System.out.println(Demo.name); \/\/ \u4e0d\u521b\u5efa\u5bf9\u8c61\uff0c\u76f4\u63a5\u7528\u7c7b\u540d\n        Demo t = new Demo();\n        t.test1();\n    }\n}\n\/\/ \u8fd0\u884c\u7ed3\u679c\uff1a\n\/\/ \u65b0\u534e\u82d1\n\/\/ name=\u65b0\u534e\u82d1, i=0, j=3<\/code><\/pre>\n<blockquote style=\"display: block; font-size: 0.9em; border-left: 3px solid #4870ac; padding: 0.5em 1em; margin: 0px; background: #f6f8fa; color: #40464f;\">\n<p style=\"margin: 1em 0px;\"><strong style=\"color: #4870ac;\">\u4e00\u53e5\u8bdd\u603b\u7ed3\uff1astatic \u8ddf\u7c7b\u8d70\u3001\u6210\u5458\u8ddf\u5bf9\u8c61\u8d70\u3001\u5c40\u90e8\u8ddf\u65b9\u6cd5\u8d70\u3001\u5757\u5185\u53d8\u91cf\u51fa\u4e86\u82b1\u62ec\u53f7\u5c31\u6ca1\u4e86\u3002<\/strong><\/p>\n<\/blockquote>\n<\/section>\n","protected":false},"excerpt":{"rendered":"<p>Java \u91cc\u53d8\u91cf\u7684\u4f5c\u7528\u57df\u53ef\u4ee5\u5206\u6210\u56db\u7ea7\uff1a\u7c7b\u7ea7\u3001\u5bf9\u8c61\u5b9e\u4f8b\u7ea7\u3001\u65b9\u6cd5\u7ea7\u3001\u5757\u7ea7\u3002\u80fd\u770b\u89c1\u8c01\u3001\u6d3b\u591a\u4e45\uff0c\u5168\u7531\u5b9a\u4e49\u4f4d\u7f6e\u51b3\u5b9a\u3002 \u7c7b [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[43],"_links":{"self":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/76"}],"collection":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=76"}],"version-history":[{"count":2,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/76\/revisions"}],"predecessor-version":[{"id":372,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=\/wp\/v2\/posts\/76\/revisions\/372"}],"wp:attachment":[{"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=76"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=76"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ai.zhousir.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=76"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}