{"id":1249,"date":"2025-02-24T13:45:49","date_gmt":"2025-02-24T05:45:49","guid":{"rendered":"https:\/\/www.tqazy.com\/?p=1249"},"modified":"2025-02-24T20:25:59","modified_gmt":"2025-02-24T12:25:59","slug":"%e9%9d%a2%e8%af%95%e7%ac%94%e8%ae%b002-java%e5%9f%ba%e7%a1%80%ef%bc%88%e4%ba%8c%ef%bc%89%ef%bc%9a%e9%9d%a2%e5%90%91%e5%af%b9%e8%b1%a1","status":"publish","type":"post","link":"https:\/\/www.tqazy.com\/?p=1249","title":{"rendered":"\u9762\u8bd5\u7b14\u8bb002-Java\u57fa\u7840\uff08\u4e8c\uff09\uff1a\u9762\u5411\u5bf9\u8c61"},"content":{"rendered":"<h1>\u4e00\u3001\u7c7b\u4e0e\u5bf9\u8c61<\/h1>\n<p><strong>1. \u8bf7\u89e3\u91ca\u7c7b\u548c\u5bf9\u8c61\u7684\u6982\u5ff5\uff0c\u4ee5\u53ca\u5b83\u4eec\u4e4b\u95f4\u7684\u5173\u7cfb<\/strong><br \/>\n<strong>\u7b54\uff1a<\/strong><\/p>\n<ul>\n<li><strong>\u7c7b<\/strong>\u662f\u5bf9\u5177\u6709\u76f8\u540c\u5c5e\u6027\u548c\u884c\u4e3a\u7684\u4e00\u7ec4\u5bf9\u8c61\u7684\u62bd\u8c61\u63cf\u8ff0\u3002<br \/>\n\u5b83\u5b9a\u4e49\u4e86\u5bf9\u8c61\u7684\u5c5e\u6027\uff08\u6210\u5458\u53d8\u91cf\uff09\u548c\u884c\u4e3a\uff08\u65b9\u6cd5\uff09\uff0c\u662f\u521b\u5efa\u5bf9\u8c61\u7684\u6a21\u677f\u3002<\/li>\n<li><strong>\u5bf9\u8c61<\/strong>\u662f\u7c7b\u7684\u5177\u4f53\u5b9e\u4f8b\uff0c\u662f\u6839\u636e\u7c7b\u521b\u5efa\u51fa\u6765\u7684\u4e00\u4e2a\u4e2a\u72ec\u7acb\u4e2a\u4f53\uff0c\u6bcf\u4e2a\u5bf9\u8c61\u90fd\u6709\u81ea\u5df1\u7684\u72b6\u6001\uff08\u5c5e\u6027\u503c\uff09\u3002<\/li>\n<li>\u7c7b\u548c\u5bf9\u8c61\u7684\u5173\u7cfb\u662f\u62bd\u8c61\u4e0e\u5177\u4f53\u7684\u5173\u7cfb\u3002<br \/>\n\u7c7b\u662f\u5bf9\u8c61\u7684\u84dd\u56fe\uff0c\u5bf9\u8c61\u662f\u7c7b\u7684\u5177\u4f53\u8868\u73b0\u3002<br \/>\n\u4f8b\u5982\uff0c\u201c\u6c7d\u8f66\u201d \u7c7b\u63cf\u8ff0\u4e86\u6c7d\u8f66\u7684\u901a\u7528\u5c5e\u6027\uff08\u989c\u8272\u3001\u54c1\u724c\u7b49\uff09\u548c\u884c\u4e3a\uff08\u884c\u9a76\u3001\u5239\u8f66\u7b49\uff09\uff0c\u800c\u67d0\u4e00\u8f86\u5177\u4f53\u7684\u7ea2\u8272\u5b9d\u9a6c\u6c7d\u8f66\u5c31\u662f \u201c\u6c7d\u8f66\u201d \u7c7b\u7684\u4e00\u4e2a\u5bf9\u8c61\u3002<\/li>\n<\/ul>\n<p><strong>2. \u7b80\u8ff0\u6784\u9020\u65b9\u6cd5\u7684\u4f5c\u7528\u548c\u7279\u70b9<\/strong><br \/>\n<strong>\u7b54\uff1a<\/strong><br \/>\n\u6784\u9020\u65b9\u6cd5\u7684\u4f5c\u7528\u662f\u5728\u521b\u5efa\u5bf9\u8c61\u65f6\u5bf9\u5bf9\u8c61\u8fdb\u884c\u521d\u59cb\u5316\u64cd\u4f5c\uff0c\u4e3a\u5bf9\u8c61\u7684\u6210\u5458\u53d8\u91cf\u8d4b\u521d\u59cb\u503c\u3002<br \/>\n\u5176\u7279\u70b9\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li><strong>\u65b9\u6cd5\u540d\u4e0e\u7c7b\u540d\u76f8\u540c\uff1a<\/strong>\u6784\u9020\u65b9\u6cd5\u7684\u540d\u79f0\u5fc5\u987b\u548c\u6240\u5728\u7c7b\u7684\u540d\u79f0\u4e00\u81f4\u3002<\/li>\n<li><strong>\u6ca1\u6709\u8fd4\u56de\u503c\u7c7b\u578b\uff1a<\/strong>\u6784\u9020\u65b9\u6cd5\u4e0d\u80fd\u6709\u8fd4\u56de\u503c\u7c7b\u578b\uff0c\u8fde void \u4e5f\u4e0d\u80fd\u6709\u3002<\/li>\n<li>\n<p><strong>\u53ef\u91cd\u8f7d\uff1a<\/strong>\u4e00\u4e2a\u7c7b\u4e2d\u53ef\u4ee5\u6709\u591a\u4e2a\u6784\u9020\u65b9\u6cd5\uff0c\u5b83\u4eec\u7684\u53c2\u6570\u5217\u8868\u4e0d\u540c\uff0c\u4ee5\u6ee1\u8db3\u4e0d\u540c\u7684\u521d\u59cb\u5316\u9700\u6c42\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code class=\"language-java\">class Person {\nString name;\nint age;\n\n\/\/ \u65e0\u53c2\u6784\u9020\u65b9\u6cd5\npublic Person() {\n    name = &quot;\u672a\u77e5&quot;;\n    age = 0;\n}\n\n\/\/ \u5e26\u53c2\u6784\u9020\u65b9\u6cd5\npublic Person(String n, int a) {\n    name = n;\nage = a;\n}\n}<\/code><\/pre>\n<\/li>\n<\/ul>\n<h1>\u4e8c\u3001\u91cd\u8f7d\u4e0e\u91cd\u5199<\/h1>\n<p><strong>1. \u4ec0\u4e48\u662f\u65b9\u6cd5\u91cd\u8f7d\uff1f\u8bf7\u4e3e\u4f8b\u8bf4\u660e\u3002<\/strong><br \/>\n<strong>\u7b54\uff1a<\/strong><br \/>\n\u65b9\u6cd5\u91cd\u8f7d\u662f\u6307\u5728\u4e00\u4e2a\u7c7b\u4e2d\u53ef\u4ee5\u5b9a\u4e49\u591a\u4e2a\u65b9\u6cd5\u540d\u76f8\u540c\uff0c\u4f46\u53c2\u6570\u5217\u8868\u4e0d\u540c\uff08\u53c2\u6570\u7684\u7c7b\u578b\u3001\u4e2a\u6570\u6216\u987a\u5e8f\u4e0d\u540c\uff09\u7684\u65b9\u6cd5\u3002<br \/>\n\u8c03\u7528\u65f6\uff0cJava \u6839\u636e\u4f20\u5165\u7684\u5b9e\u53c2\u7c7b\u578b\u3001\u4e2a\u6570\u548c\u987a\u5e8f\u6765\u51b3\u5b9a\u8c03\u7528\u54ea\u4e2a\u65b9\u6cd5\u3002<br \/>\n\u4f8b\u5982\uff1a<\/p>\n<pre><code class=\"language-java\">class Calculator {\n    public int add(int a, int b) {\n        return a + b;\n    }\n    public double add(double a, double b) {\n    return a + b;\n    }\n}<\/code><\/pre>\n<p><strong>2. \u65b9\u6cd5\u91cd\u8f7d\u662f\u5426\u4e0e\u8fd4\u56de\u503c\u7c7b\u578b\u6709\u5173\uff1f<\/strong><br \/>\n<strong>\u7b54\uff1a<\/strong><br \/>\n\u65b9\u6cd5\u91cd\u8f7d\u4e0e\u8fd4\u56de\u503c\u7c7b\u578b\u65e0\u5173\u3002<\/p>\n<p><strong>3. \u4ec0\u4e48\u662f\u65b9\u6cd5\u91cd\u5199\uff1f\u91cd\u5199\u9700\u8981\u6ee1\u8db3\u54ea\u4e9b\u6761\u4ef6\uff1f<\/strong><br \/>\n<strong>\u7b54\uff1a<\/strong><br \/>\n\u65b9\u6cd5\u91cd\u5199\u662f\u6307\u5b50\u7c7b\u91cd\u65b0\u5b9a\u4e49\u7236\u7c7b\u4e2d\u5df2\u6709\u7684\u65b9\u6cd5\u3002<br \/>\n\u9700\u8981\u6ee1\u8db3\u4ee5\u4e0b\u6761\u4ef6\uff1a<\/p>\n<ul>\n<li>\u65b9\u6cd5\u540d\u3001\u53c2\u6570\u5217\u8868\u548c\u8fd4\u56de\u503c\u7c7b\u578b\u5fc5\u987b\u4e0e\u7236\u7c7b\u88ab\u91cd\u5199\u7684\u65b9\u6cd5\u76f8\u540c\uff08Java 5 \u5f00\u59cb\uff0c\u8fd4\u56de\u503c\u7c7b\u578b\u53ef\u4ee5\u662f\u7236\u7c7b\u65b9\u6cd5\u8fd4\u56de\u503c\u7c7b\u578b\u7684\u5b50\u7c7b\uff0c\u5373\u534f\u53d8\u8fd4\u56de\u7c7b\u578b\uff09\u3002<\/li>\n<li>\u8bbf\u95ee\u6743\u9650\u4e0d\u80fd\u6bd4\u7236\u7c7b\u88ab\u91cd\u5199\u65b9\u6cd5\u66f4\u4e25\u683c\u3002<\/li>\n<li>\u4e0d\u80fd\u629b\u51fa\u6bd4\u7236\u7c7b\u88ab\u91cd\u5199\u65b9\u6cd5\u66f4\u591a\u3001\u66f4\u5bbd\u6cdb\u7684\u5f02\u5e38\u3002<\/li>\n<\/ul>\n<p>\u4f8b\u5982\uff1a<\/p>\n<pre><code class=\"language-java\">\/\/ \u7236\u7c7b\nclass Animal {\n    public void sound() {\n        System.out.println(&quot;\u52a8\u7269\u53d1\u58f0&quot;);\n    }\n}\n\/\/ \u5b50\u7c7b\nclass Dog extends Animal {\n    @Override\n    public void sound() {\n        System.out.println(&quot;\u6c6a\u6c6a\u6c6a&quot;);\n    }\n}<\/code><\/pre>\n<p><strong>4. final\u3001static\u3001private \u4fee\u9970\u7684\u65b9\u6cd5\u80fd\u5426\u88ab\u91cd\u5199\uff1f<\/strong><br \/>\n<strong>\u7b54\uff1a<\/strong><\/p>\n<ul>\n<li><code>final<\/code> \u4fee\u9970\u7684\u65b9\u6cd5\u4e0d\u80fd\u88ab\u91cd\u5199\u3002<br \/>\n\u56e0\u4e3a <code>final<\/code> \u5173\u952e\u5b57\u8868\u793a\u8be5\u65b9\u6cd5\u4e0d\u80fd\u88ab\u4fee\u6539\uff0c\u4fdd\u8bc1\u4e86\u65b9\u6cd5\u7684\u7a33\u5b9a\u6027\u3002<\/li>\n<li><code>static<\/code> \u4fee\u9970\u7684\u65b9\u6cd5\u4e0d\u80fd\u88ab\u91cd\u5199\uff0c\u53ea\u80fd\u88ab\u9690\u85cf\u3002<br \/>\n\u9759\u6001\u65b9\u6cd5\u5c5e\u4e8e\u7c7b\uff0c\u800c\u4e0d\u662f\u5bf9\u8c61\uff0c\u5b50\u7c7b\u53ef\u4ee5\u5b9a\u4e49\u4e0e\u7236\u7c7b\u9759\u6001\u65b9\u6cd5\u76f8\u540c\u7684\u65b9\u6cd5\uff0c\u4f46\u8fd9\u4e0d\u662f\u91cd\u5199\uff0c\u53ea\u662f\u9690\u85cf\u4e86\u7236\u7c7b\u7684\u9759\u6001\u65b9\u6cd5\u3002<\/li>\n<li><code>private<\/code> \u4fee\u9970\u7684\u65b9\u6cd5\u4e0d\u80fd\u88ab\u91cd\u5199\u3002<br \/>\n\u56e0\u4e3a <code>private<\/code> \u65b9\u6cd5\u53ea\u80fd\u5728\u672c\u7c7b\u4e2d\u8bbf\u95ee\uff0c\u5b50\u7c7b\u65e0\u6cd5\u8bbf\u95ee\u5230\u7236\u7c7b\u7684 <code>private<\/code> \u65b9\u6cd5\uff0c\u4e5f\u5c31\u65e0\u6cd5\u91cd\u5199\u3002<\/li>\n<\/ul>\n<p><strong>5. \u8bf7\u7b80\u8981\u56de\u7b54\u65b9\u6cd5\u91cd\u8f7d\u548c\u65b9\u6cd5\u91cd\u5199\u7684\u76f8\u540c\u4e0e\u4e0d\u540c\uff1f<\/strong><br \/>\n<strong>\u7b54\uff1a<\/strong><\/p>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: center;\"><\/th>\n<th style=\"text-align: center;\"><strong>\u65b9\u6cd5\u91cd\u8f7d<\/strong><\/th>\n<th style=\"text-align: center;\"><strong>\u65b9\u6cd5\u91cd\u5199<\/strong><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: center;\"><strong>\u5b9a\u4f4d\u4f4d\u7f6e<\/strong><\/td>\n<td style=\"text-align: center;\">\u540c\u4e00\u4e2a\u7c7b\u4e2d<\/td>\n<td style=\"text-align: center;\">\u5b50\u7c7b\u548c\u7236\u7c7b<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\"><strong>\u65b9\u6cd5\u540d<\/strong><\/td>\n<td style=\"text-align: center;\">\u8981\u76f8\u540c<\/td>\n<td style=\"text-align: center;\">\u8981\u76f8\u540c<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\"><strong>\u53c2\u6570\u5217\u8868<\/strong><\/td>\n<td style=\"text-align: center;\">\u4e0d\u540c<\/td>\n<td style=\"text-align: center;\">\u5fc5\u987b\u76f8\u540c<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\"><strong>\u8fd4\u56de\u503c\u7c7b\u578b<\/strong><\/td>\n<td style=\"text-align: center;\">\u65e0\u5173<\/td>\n<td style=\"text-align: center;\">\u76f8\u540c\u6216\u4e3a\u534f\u53d8\u8fd4\u56de\u7c7b\u578b<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\"><strong>\u8bbf\u95ee\u6743\u9650<\/strong><\/td>\n<td style=\"text-align: center;\">\u65e0\u5173<\/td>\n<td style=\"text-align: center;\">\u5b50\u7c7b\u65b9\u6cd5\u4e0d\u80fd\u6bd4\u7236\u7c7b\u66f4\u4e25\u683c<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\"><strong>\u5f02\u5e38<\/strong><\/td>\n<td style=\"text-align: center;\">\u65e0\u5173<\/td>\n<td style=\"text-align: center;\">\u5b50\u7c7b\u65b9\u6cd5\u4e0d\u80fd\u629b\u51fa\u6bd4\u7236\u7c7b\u66f4\u591a\u3001\u66f4\u5bbd\u6cdb\u7684\u5f02\u5e38<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h1>\u4e09\u3001\u5c01\u88c5\u3001\u7ee7\u627f\u3001\u591a\u6001<\/h1>\n<p><strong>1. \u4ec0\u4e48\u662f\u5c01\u88c5\uff0c\u4e3a\u4ec0\u4e48\u8981\u4f7f\u7528\u5c01\u88c5\uff1f<\/strong><br \/>\n<strong>\u7b54\uff1a<\/strong><br \/>\n\u5c01\u88c5\u662f\u5c06\u5bf9\u8c61\u7684\u5c5e\u6027\u548c\u5b9e\u73b0\u7ec6\u8282\u9690\u85cf\u8d77\u6765\uff0c\u4ec5\u5bf9\u5916\u63d0\u4f9b\u516c\u5171\u7684\u8bbf\u95ee\u65b9\u5f0f\uff08\u5982 getter \u548c setter \u65b9\u6cd5\uff09\u3002<br \/>\n\u4f7f\u7528\u5c01\u88c5\u7684\u539f\u56e0\uff1a<\/p>\n<ul>\n<li>\u63d0\u9ad8\u4ee3\u7801\u7684\u5b89\u5168\u6027\uff0c\u9632\u6b62\u5916\u90e8\u968f\u610f\u4fee\u6539\u5bf9\u8c61\u7684\u5c5e\u6027\uff1b<\/li>\n<li>\u589e\u5f3a\u4ee3\u7801\u7684\u53ef\u7ef4\u62a4\u6027\uff0c\u5f53\u5185\u90e8\u5b9e\u73b0\u6539\u53d8\u65f6\uff0c\u53ea\u8981\u5bf9\u5916\u63a5\u53e3\u4e0d\u53d8\uff0c\u5c31\u4e0d\u4f1a\u5f71\u54cd\u5176\u4ed6\u4ee3\u7801\uff1b<\/li>\n<li>\u5b9e\u73b0\u4fe1\u606f\u9690\u85cf\uff0c\u8ba9\u4f7f\u7528\u8005\u53ea\u9700\u5173\u6ce8\u63a5\u53e3\uff0c\u65e0\u9700\u4e86\u89e3\u5177\u4f53\u5b9e\u73b0\u3002<\/li>\n<\/ul>\n<p><strong>2. \u5982\u4f55\u5728 Java \u4e2d\u5b9e\u73b0\u5c01\u88c5\uff1f<\/strong><br \/>\n<strong>\u7b54\uff1a<\/strong><br \/>\n\u9996\u5148\u5c06\u7c7b\u7684\u5c5e\u6027\u58f0\u660e\u4e3a <code>private<\/code>\uff0c\u9650\u5236\u5916\u90e8\u76f4\u63a5\u8bbf\u95ee\u3002<br \/>\n\u7136\u540e\u63d0\u4f9b\u516c\u5171\u7684 getter \u65b9\u6cd5\u7528\u4e8e\u83b7\u53d6\u5c5e\u6027\u503c\uff0csetter \u65b9\u6cd5\u7528\u4e8e\u8bbe\u7f6e\u5c5e\u6027\u503c\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code class=\"language-java\">class Student {\n    private String name;\n    public String getName() {\n        return name;\n    }\n    public void setName(String name) {\n        this.name = name;\n    }\n}<\/code><\/pre>\n<p><strong>3. \u4ec0\u4e48\u662f\u7ee7\u627f\uff0c\u7ee7\u627f\u6709\u4ec0\u4e48\u4f5c\u7528\uff1f<\/strong><br \/>\n<strong>\u7b54\uff1a<\/strong><br \/>\n\u7ee7\u627f\u662f\u6307\u4e00\u4e2a\u7c7b\uff08\u5b50\u7c7b\uff09\u53ef\u4ee5\u7ee7\u627f\u53e6\u4e00\u4e2a\u7c7b\uff08\u7236\u7c7b\uff09\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\u3002<br \/>\n\u5176\u4f5c\u7528\u5305\u62ec\uff1a<\/p>\n<ul>\n<li>\u5b9e\u73b0\u4ee3\u7801\u590d\u7528\uff0c\u907f\u514d\u91cd\u590d\u7f16\u5199\u76f8\u540c\u7684\u4ee3\u7801\uff1b<\/li>\n<li>\u5efa\u7acb\u7c7b\u4e4b\u95f4\u7684\u5c42\u6b21\u5173\u7cfb\uff0c\u4fbf\u4e8e\u4ee3\u7801\u7684\u7ec4\u7ec7\u548c\u7ba1\u7406\uff1b<\/li>\n<li>\u4e3a\u591a\u6001\u63d0\u4f9b\u57fa\u7840\u3002<\/li>\n<\/ul>\n<p><strong>4. Java \u4e2d\u7ee7\u627f\u6709\u54ea\u4e9b\u9650\u5236\uff1f<\/strong><br \/>\n<strong>\u7b54\uff1a<\/strong><br \/>\nJava \u53ea\u652f\u6301\u5355\u7ee7\u627f\uff0c\u5373\u4e00\u4e2a\u5b50\u7c7b\u53ea\u80fd\u6709\u4e00\u4e2a\u76f4\u63a5\u7236\u7c7b\uff0c\u4f46\u53ef\u4ee5\u5b9e\u73b0\u591a\u5c42\u7ee7\u627f\u3002<br \/>\n\u53e6\u5916\uff0cprivate \u6210\u5458\u4e0d\u80fd\u88ab\u7ee7\u627f\uff0c\u6784\u9020\u65b9\u6cd5\u4e5f\u4e0d\u80fd\u88ab\u7ee7\u627f\uff0c\u4f46\u5b50\u7c7b\u6784\u9020\u65b9\u6cd5\u4e2d\u53ef\u4ee5\u901a\u8fc7 super() \u8c03\u7528\u7236\u7c7b\u6784\u9020\u65b9\u6cd5\u3002<\/p>\n<p><strong>5. \u5b9e\u73b0\u4e00\u4e2a\u7ee7\u627f\u6548\u679c<\/strong><\/p>\n<pre><code class=\"language-java\">\/\/ \u5b9a\u4e49\u4e00\u4e2a\u7236\u7c7b\uff1aAnimal\nclass Animal {\n    \/\/ \u7236\u7c7b\u7684\u5c5e\u6027\n    protected String name;\n    \/\/ \u7236\u7c7b\u7684\u6784\u9020\u65b9\u6cd5\n    public Animal(String name) {\n        this.name = name;\n    }\n    \/\/ \u7236\u7c7b\u7684\u65b9\u6cd5\n    public void eat() {\n        System.out.println(name + &quot; \u6b63\u5728\u5403\u4e1c\u897f&quot;);\n    }\n    public void sleep() {\n        System.out.println(name + &quot; \u6b63\u5728\u7761\u89c9&quot;);\n    }\n}\n\n\/\/ \u5b9a\u4e49\u4e00\u4e2a\u5b50\u7c7b\uff1aDog\uff0c\u7ee7\u627f\u81ea Animal \u7c7b\nclass Dog extends Animal {\n    \/\/ \u5b50\u7c7b\u7279\u6709\u7684\u5c5e\u6027\n    private String breed;\n    \/\/ \u5b50\u7c7b\u7684\u6784\u9020\u65b9\u6cd5\n    public Dog(String name, String breed) {\n        \/\/ \u8c03\u7528\u7236\u7c7b\u7684\u6784\u9020\u65b9\u6cd5\u6765\u521d\u59cb\u5316\u4ece\u7236\u7c7b\u7ee7\u627f\u7684\u5c5e\u6027\n        super(name);\n        this.breed = breed;\n    }\n    \/\/ \u5b50\u7c7b\u91cd\u5199\u7236\u7c7b\u7684\u65b9\u6cd5\n    @Override\n    public void eat() {\n        System.out.println(name + &quot;\uff08\u54c1\u79cd\uff1a&quot; + breed + &quot;\uff09\u6b63\u5728\u5543\u9aa8\u5934&quot;);\n    }\n    \/\/ \u5b50\u7c7b\u7279\u6709\u7684\u65b9\u6cd5\n    public void bark() {\n        System.out.println(name + &quot;\uff08\u54c1\u79cd\uff1a&quot; + breed + &quot;\uff09\u6b63\u5728\u6c6a\u6c6a\u53eb&quot;);\n    }\n}\n\n\/\/ \u6d4b\u8bd5\u7c7b\npublic class InheritanceExample {\n    public static void main(String[] args) {\n        \/\/ \u521b\u5efa Dog \u7c7b\u7684\u5bf9\u8c61\n        Dog dog = new Dog(&quot;\u65fa\u8d22&quot;, &quot;\u91d1\u6bdb&quot;);\n        \/\/ \u8c03\u7528\u4ece\u7236\u7c7b\u7ee7\u627f\u7684\u65b9\u6cd5\n        dog.sleep();\n        \/\/ \u8c03\u7528\u5b50\u7c7b\u91cd\u5199\u7684\u65b9\u6cd5\n        dog.eat();\n        \/\/ \u8c03\u7528\u5b50\u7c7b\u7279\u6709\u7684\u65b9\u6cd5\n        dog.bark();\n    }\n}<\/code><\/pre>\n<p>\u8f93\u51fa\u7ed3\u679c\uff1a<\/p>\n<pre><code class=\"language-txt\">\u65fa\u8d22 \u6b63\u5728\u7761\u89c9\n\u65fa\u8d22\uff08\u54c1\u79cd\uff1a\u91d1\u6bdb\uff09\u6b63\u5728\u5543\u9aa8\u5934\n\u65fa\u8d22\uff08\u54c1\u79cd\uff1a\u91d1\u6bdb\uff09\u6b63\u5728\u6c6a\u6c6a\u53eb<\/code><\/pre>\n<p><strong>\u4ee3\u7801\u89e3\u91ca<\/strong><\/p>\n<ol>\n<li>\n<p>\u7236\u7c7b Animal\uff1a<\/p>\n<ul>\n<li>\u5305\u542b\u4e00\u4e2a\u53d7\u4fdd\u62a4\u7684\u5c5e\u6027 name\uff0c\u7528\u4e8e\u5b58\u50a8\u52a8\u7269\u7684\u540d\u5b57\u3002<\/li>\n<li>\u6709\u4e00\u4e2a\u6784\u9020\u65b9\u6cd5 Animal(String name) \u7528\u4e8e\u521d\u59cb\u5316 name \u5c5e\u6027\u3002<\/li>\n<li>\u5b9a\u4e49\u4e86\u4e24\u4e2a\u65b9\u6cd5 eat() \u548c sleep()\uff0c\u5206\u522b\u8868\u793a\u52a8\u7269\u5403\u4e1c\u897f\u548c\u7761\u89c9\u7684\u884c\u4e3a\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u5b50\u7c7b Dog\uff1a<\/p>\n<ul>\n<li>\u4f7f\u7528 extends \u5173\u952e\u5b57\u7ee7\u627f\u81ea Animal \u7c7b\u3002<\/li>\n<li>\u6709\u4e00\u4e2a\u7279\u6709\u7684\u5c5e\u6027 breed\uff0c\u7528\u4e8e\u5b58\u50a8\u72d7\u7684\u54c1\u79cd\u3002<\/li>\n<li>\u6784\u9020\u65b9\u6cd5 Dog(String name, String breed) \u4e2d\u4f7f\u7528 super(name) \u8c03\u7528\u7236\u7c7b\u7684\u6784\u9020\u65b9\u6cd5\u6765\u521d\u59cb\u5316\u4ece\u7236\u7c7b\u7ee7\u627f\u7684 name \u5c5e\u6027\u3002<\/li>\n<li>\u91cd\u5199\u4e86\u7236\u7c7b\u7684 eat() \u65b9\u6cd5\uff0c\u63d0\u4f9b\u4e86\u72d7\u5403\u4e1c\u897f\u7684\u7279\u5b9a\u884c\u4e3a\u3002<\/li>\n<li>\u5b9a\u4e49\u4e86\u4e00\u4e2a\u7279\u6709\u7684\u65b9\u6cd5 bark()\uff0c\u8868\u793a\u72d7\u6c6a\u6c6a\u53eb\u7684\u884c\u4e3a\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u6d4b\u8bd5\u7c7b InheritanceExample\uff1a<\/p>\n<ul>\n<li>\u5728 main \u65b9\u6cd5\u4e2d\u521b\u5efa\u4e86 Dog \u7c7b\u7684\u5bf9\u8c61 dog\u3002<\/li>\n<li>\u8c03\u7528\u4e86\u4ece\u7236\u7c7b\u7ee7\u627f\u7684 sleep() \u65b9\u6cd5\u3001\u5b50\u7c7b\u91cd\u5199\u7684 eat() \u65b9\u6cd5\u4ee5\u53ca\u5b50\u7c7b\u7279\u6709\u7684 bark() \u65b9\u6cd5\uff0c\u5c55\u793a\u4e86\u7ee7\u627f\u548c\u65b9\u6cd5\u91cd\u5199\u7684\u6548\u679c\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><strong>6. \u4ec0\u4e48\u662f\u591a\u6001\uff0c\u5982\u4f55\u5b9e\u73b0\u591a\u6001\uff1f<\/strong><br \/>\n\u591a\u6001\u662f\u6307\u540c\u4e00\u4e2a\u65b9\u6cd5\u8c03\u7528\uff0c\u7531\u4e8e\u5bf9\u8c61\u4e0d\u540c\u53ef\u80fd\u4f1a\u4ea7\u751f\u4e0d\u540c\u7684\u884c\u4e3a\u3002<br \/>\n\u5b9e\u73b0\u591a\u6001\u6709\u4e09\u4e2a\u5fc5\u8981\u6761\u4ef6\uff1a<\/p>\n<ul>\n<li>\u7ee7\u627f<\/li>\n<li>\u65b9\u6cd5\u91cd\u5199<\/li>\n<li>\u7236\u7c7b\u5f15\u7528\u6307\u5411\u5b50\u7c7b\u5bf9\u8c61<\/li>\n<\/ul>\n<p>\u4f8b\u5982\uff1a<\/p>\n<pre><code class=\"language-java\">\/\/ \u7236\u7c7b\uff1a\u52a8\u7269\u7c7b\nclass Animal {\n    public void sound() {\n        System.out.println(&quot;\u52a8\u7269\u53d1\u58f0&quot;);\n    }\n}\n\/\/ \u5b50\u7c7b\uff1a\u72d7\u7c7b\nclass Dog extends Animal {\n    @Override\n    public void sound() {\n        System.out.println(&quot;\u6c6a\u6c6a\u6c6a&quot;);\n    }\n}\n\/\/ \u5b50\u7c7b\uff1a\u732b\u7c7b\nclass Cat extends Animal {\n    @Override\n    public void sound() {\n        System.out.println(&quot;\u55b5\u55b5\u55b5&quot;);\n    }\n}\n\/\/ \u6d4b\u8bd5\npublic class Main {\n    public static void main(String[] args) {\n        Animal animal = new Dog();\n        animal.sound(); \/\/ \u8f93\u51fa\uff1a\u6c6a\u6c6a\u6c6a\n\n        animal = new Cat();\n        animal.sound(); \/\/ \u8f93\u51fa\uff1a\u55b5\u55b5\u55b5\n    }\n}<\/code><\/pre>\n<h1>\u56db\u3001\u62bd\u8c61\u7c7b\u4e0e\u63a5\u53e3<\/h1>\n<p><strong>1. \u8bf7\u7b80\u8ff0\u62bd\u8c61\u7c7b\u548c\u63a5\u53e3\u7684\u6982\u5ff5\u53ca\u533a\u522b<\/strong><br \/>\n<strong>\u7b54\uff1a<\/strong><br \/>\n<strong>\u62bd\u8c61\u7c7b<\/strong>\u662f\u7528 <code>abstract<\/code> \u5173\u952e\u5b57\u4fee\u9970\u7684\u7c7b\uff0c\u5b83\u53ef\u4ee5\u5305\u542b\u62bd\u8c61\u65b9\u6cd5\uff08\u53ea\u6709\u58f0\u660e\uff0c\u6ca1\u6709\u5b9e\u73b0\uff09\u548c\u5177\u4f53\u65b9\u6cd5\uff0c\u4e5f\u53ef\u4ee5\u6709\u6210\u5458\u53d8\u91cf\u3002<br \/>\n<strong>\u63a5\u53e3<\/strong>\u662f\u4e00\u79cd\u7279\u6b8a\u7684\u62bd\u8c61\u7c7b\u578b\uff0c\u5b83\u53ea\u5305\u542b\u62bd\u8c61\u65b9\u6cd5\uff08Java 8 \u53ca\u4ee5\u540e\u53ef\u5305\u542b\u9ed8\u8ba4\u65b9\u6cd5\u548c\u9759\u6001\u65b9\u6cd5\uff09\u548c\u5e38\u91cf\u3002<\/p>\n<ul>\n<li><strong>\u8bed\u6cd5\u5c42\u9762\uff1a<\/strong>\n<ul>\n<li><strong>\u62bd\u8c61\u7c7b\uff1a<\/strong>\n<ul>\n<li>\u7528 <code>abstract class<\/code> \u5b9a\u4e49\uff1b<\/li>\n<li>\u53ef\u4ee5\u6709\u6784\u9020\u65b9\u6cd5\uff1b<\/li>\n<li>\u6210\u5458\u53d8\u91cf\u53ef\u4ee5\u662f\u5404\u79cd\u7c7b\u578b\uff1b<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u63a5\u53e3\uff1a<\/strong>\n<ul>\n<li>\u7528 <code>interface<\/code> \u5b9a\u4e49\uff1b<\/li>\n<li>\u6ca1\u6709\u6784\u9020\u65b9\u6cd5\uff1b<\/li>\n<li>\u6210\u5458\u53d8\u91cf\u9ed8\u8ba4\u662f public static final \u4fee\u9970\u7684\u5e38\u91cf<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u8bbe\u8ba1\u5c42\u9762\uff1a<\/strong>\n<ul>\n<li>\u62bd\u8c61\u7c7b\u662f\u5bf9\u4e00\u7c7b\u4e8b\u7269\u7684\u62bd\u8c61\uff0c\u662f\u4e00\u79cd \u201cis &#8211; a\u201d \u5173\u7cfb\uff1b<\/li>\n<li>\u63a5\u53e3\u662f\u5bf9\u884c\u4e3a\u7684\u62bd\u8c61\uff0c\u662f\u4e00\u79cd \u201clike &#8211; a\u201d \u5173\u7cfb\u3002<br \/>\n<strong>\u4f7f\u7528\u5c42\u9762\uff1a<\/strong> \u4e00\u4e2a\u7c7b\u53ea\u80fd\u7ee7\u627f\u4e00\u4e2a\u62bd\u8c61\u7c7b\uff0c\u4f46\u53ef\u4ee5\u5b9e\u73b0\u591a\u4e2a\u63a5\u53e3\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><strong>2. \u4ec0\u4e48\u65f6\u5019\u4f7f\u7528\u62bd\u8c61\u7c7b\uff0c\u4ec0\u4e48\u65f6\u5019\u4f7f\u7528\u63a5\u53e3\uff1f<\/strong><br \/>\n<strong>\u7b54\uff1a<\/strong><\/p>\n<ul>\n<li><strong>\u62bd\u8c61\u7c7b\uff1a<\/strong>\u5f53\u9700\u8981\u4e3a\u5b50\u7c7b\u63d0\u4f9b\u516c\u5171\u7684\u65b9\u6cd5\u5b9e\u73b0\u548c\u6210\u5458\u53d8\u91cf\uff0c\u4e14\u5b50\u7c7b\u4e4b\u95f4\u6709\u5171\u540c\u7684\u5c5e\u6027\u548c\u884c\u4e3a\uff0c\u5c5e\u4e8e\u540c\u4e00\u7c7b\u4e8b\u7269\u65f6\uff0c\u4f7f\u7528\u62bd\u8c61\u7c7b\u3002<br \/>\n\u4f8b\u5982\uff0c\u4e0d\u540c\u79cd\u7c7b\u7684\u6c7d\u8f66\u90fd\u6709\u542f\u52a8\u3001\u505c\u6b62\u7b49\u884c\u4e3a\uff0c\u53ef\u5c06\u6c7d\u8f66\u62bd\u8c61\u6210\u62bd\u8c61\u7c7b\u3002<\/li>\n<li><strong>\u63a5\u53e3\uff1a<\/strong>\u5f53\u9700\u8981\u5b9a\u4e49\u4e00\u7ec4\u884c\u4e3a\u89c4\u8303\uff0c\u591a\u4e2a\u4e0d\u76f8\u5173\u7684\u7c7b\u90fd\u8981\u9075\u5faa\u8fd9\u4e9b\u89c4\u8303\u65f6\uff0c\u4f7f\u7528\u63a5\u53e3\u3002<br \/>\n\u4f8b\u5982\uff0c\u98de\u673a\u548c\u9e1f\u90fd\u80fd\u98de\uff0c\u201c\u98de\u201d \u8fd9\u4e2a\u884c\u4e3a\u53ef\u4ee5\u5b9a\u4e49\u6210\u63a5\u53e3\u3002<\/li>\n<\/ul>\n<p><strong>3. \u4e00\u4e2a\u7c7b\u80fd\u5426\u540c\u65f6\u7ee7\u627f\u62bd\u8c61\u7c7b\u548c\u5b9e\u73b0\u63a5\u53e3\uff1f<\/strong><br \/>\n<strong>\u7b54\uff1a<\/strong> \u53ef\u4ee5\u3002\u4f8b\u5982\uff1a<code class=\"kb-btn\">class Bird extends Animal implements Flyable {...}<\/code><\/p>\n<p><strong>4. \u5b9e\u73b0\u4e00\u4e2a\u540c\u65f6\u7ee7\u627f\u62bd\u8c61\u7c7b\u548c\u5b9e\u73b0\u63a5\u53e3\u4f8b\u5b50<\/strong><\/p>\n<pre><code class=\"language-java\">\/\/ \u5b9a\u4e49\u62bd\u8c61\u7c7b\uff1a\u5f62\u72b6\u7c7b\nabstract class Shape {\n    \/\/ \u62bd\u8c61\u65b9\u6cd5\uff0c\u7528\u4e8e\u8ba1\u7b97\u9762\u79ef\uff0c\u5177\u4f53\u5b9e\u73b0\u7531\u5b50\u7c7b\u5b8c\u6210\n    public abstract double area();\n\n    \/\/ \u5177\u4f53\u65b9\u6cd5\uff0c\u6240\u6709\u7ee7\u627f\u8be5\u62bd\u8c61\u7c7b\u7684\u5b50\u7c7b\u90fd\u53ef\u4f7f\u7528\n    public void display() {\n        System.out.println(&quot;\u8fd9\u662f\u4e00\u4e2a\u5f62\u72b6\u3002&quot;);\n    }\n}\n\n\/\/ \u5b9a\u4e49\u63a5\u53e3\uff1a\u989c\u8272\u63a5\u53e3\ninterface Colorable {\n    \/\/ \u63a5\u53e3\u4e2d\u7684\u62bd\u8c61\u65b9\u6cd5\uff0c\u7528\u4e8e\u8bbe\u7f6e\u989c\u8272\n    void setColor(String color);\n\n    \/\/ Java 8 \u53ca\u4ee5\u540e\u652f\u6301\u7684\u9ed8\u8ba4\u65b9\u6cd5\uff0c\u63d0\u4f9b\u4e86\u9ed8\u8ba4\u5b9e\u73b0\n    default void showColorInfo() {\n        System.out.println(&quot;\u8fd9\u662f\u4e00\u4e2a\u6709\u989c\u8272\u7684\u5f62\u72b6\u3002&quot;);\n    }\n}\n\n\/\/ \u6d4b\u8bd5\u7c7b\uff0c\u7ee7\u627f\u62bd\u8c61\u7c7b Shape \u5e76\u5b9e\u73b0\u63a5\u53e3 Colorable\nclass Circle extends Shape implements Colorable {\n    private double radius;\n    private String color;\n\n    public Circle(double radius) {\n        this.radius = radius;\n    }\n\n    \/\/ \u5b9e\u73b0\u62bd\u8c61\u7c7b\u7684\u62bd\u8c61\u65b9\u6cd5\uff0c\u8ba1\u7b97\u5706\u5f62\u9762\u79ef\n    @Override\n    public double area() {\n        return Math.PI * radius * radius;\n    }\n\n    \/\/ \u5b9e\u73b0\u63a5\u53e3\u7684\u62bd\u8c61\u65b9\u6cd5\uff0c\u8bbe\u7f6e\u989c\u8272\n    @Override\n    public void setColor(String color) {\n        this.color = color;\n        System.out.println(&quot;\u5706\u5f62\u7684\u989c\u8272\u8bbe\u7f6e\u4e3a\uff1a&quot; + color);\n    }\n\n    \/\/ \u53ef\u4ee5\u91cd\u5199\u63a5\u53e3\u7684\u9ed8\u8ba4\u65b9\u6cd5\n    @Override\n    public void showColorInfo() {\n        System.out.println(&quot;\u8fd9\u662f\u4e00\u4e2a\u989c\u8272\u4e3a &quot; + color + &quot; \u7684\u5706\u5f62\u3002&quot;);\n    }\n}\n\n\/\/ \u4e3b\u7c7b\uff0c\u7528\u4e8e\u6d4b\u8bd5\npublic class Main {\n    public static void main(String[] args) {\n        Circle circle = new Circle(5.0);\n\n        \/\/ \u8c03\u7528\u62bd\u8c61\u7c7b\u7684\u5177\u4f53\u65b9\u6cd5\n        circle.display();\n\n        \/\/ \u8c03\u7528\u5b9e\u73b0\u62bd\u8c61\u7c7b\u62bd\u8c61\u65b9\u6cd5\u7684\u7ed3\u679c\n        System.out.println(&quot;\u5706\u5f62\u7684\u9762\u79ef\u662f\uff1a&quot; + circle.area());\n\n        \/\/ \u8c03\u7528\u63a5\u53e3\u7684\u62bd\u8c61\u65b9\u6cd5\n        circle.setColor(&quot;\u7ea2\u8272&quot;);\n\n        \/\/ \u8c03\u7528\u63a5\u53e3\u7684\u9ed8\u8ba4\u65b9\u6cd5\n        circle.showColorInfo();\n    }\n}<\/code><\/pre>\n<p><strong>\u4ee3\u7801\u89e3\u91ca\uff1a<\/strong><br \/>\n<strong>1. \u62bd\u8c61\u7c7b Shape\uff1a<\/strong><\/p>\n<ul>\n<li>\u5305\u542b\u62bd\u8c61\u65b9\u6cd5 area()\uff0c\u8be5\u65b9\u6cd5\u6ca1\u6709\u5177\u4f53\u5b9e\u73b0\uff0c\u9700\u8981\u5b50\u7c7b\u53bb\u5b9e\u73b0\u3002<\/li>\n<li>\u5305\u542b\u5177\u4f53\u65b9\u6cd5 display()\uff0c\u6240\u6709\u7ee7\u627f\u8be5\u62bd\u8c61\u7c7b\u7684\u5b50\u7c7b\u90fd\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u8fd9\u4e2a\u65b9\u6cd5\u3002<br \/>\n<strong>2. \u63a5\u53e3 Colorable\uff1a<\/strong><\/li>\n<li>\u5305\u542b\u62bd\u8c61\u65b9\u6cd5 setColor(String color)\uff0c\u5b9e\u73b0\u8be5\u63a5\u53e3\u7684\u7c7b\u5fc5\u987b\u5b9e\u73b0\u8fd9\u4e2a\u65b9\u6cd5\u3002<\/li>\n<li>\u5305\u542b\u9ed8\u8ba4\u65b9\u6cd5 showColorInfo()\uff0c\u63d0\u4f9b\u4e86\u9ed8\u8ba4\u7684\u5b9e\u73b0\uff0c\u5b9e\u73b0\u7c7b\u53ef\u4ee5\u9009\u62e9\u91cd\u5199\u8be5\u65b9\u6cd5\u3002<br \/>\n<strong>3. \u6d4b\u8bd5\u7c7b Circle\uff1a<\/strong><\/li>\n<li>\u7ee7\u627f\u81ea\u62bd\u8c61\u7c7b Shape\uff0c\u5b9e\u73b0\u4e86 area() \u65b9\u6cd5\u6765\u8ba1\u7b97\u5706\u5f62\u7684\u9762\u79ef\u3002<\/li>\n<li>\u5b9e\u73b0\u4e86\u63a5\u53e3 Colorable\uff0c\u5b9e\u73b0\u4e86 setColor(String color) \u65b9\u6cd5\u6765\u8bbe\u7f6e\u5706\u5f62\u7684\u989c\u8272\uff0c\u5e76\u4e14\u91cd\u5199\u4e86 showColorInfo() \u65b9\u6cd5\u4ee5\u63d0\u4f9b\u7279\u5b9a\u7684\u989c\u8272\u4fe1\u606f\u3002<br \/>\n<strong>4. \u4e3b\u7c7b Main\uff1a<\/strong><\/li>\n<li>\u521b\u5efa\u4e86 Circle \u7c7b\u7684\u5bf9\u8c61\u3002<\/li>\n<li>\u8c03\u7528\u4e86\u62bd\u8c61\u7c7b\u7684\u5177\u4f53\u65b9\u6cd5 display()\u3002<\/li>\n<li>\u8c03\u7528\u4e86\u5b9e\u73b0\u62bd\u8c61\u7c7b\u62bd\u8c61\u65b9\u6cd5 area() \u7684\u7ed3\u679c\u3002<\/li>\n<li>\u8c03\u7528\u4e86\u63a5\u53e3\u7684\u62bd\u8c61\u65b9\u6cd5 setColor(String color) \u548c\u9ed8\u8ba4\u65b9\u6cd5 showColorInfo()\u3002<\/li>\n<\/ul>\n<h1>\u4e94\u3001\u5185\u90e8\u7c7b<\/h1>\n<p><strong>1. \u5185\u90e8\u7c7b\u6709\u54ea\u4e9b\u7c7b\u578b\uff0c\u5b83\u4eec\u7684\u8bbf\u95ee\u6743\u9650\u6709\u4f55\u4e0d\u540c\uff1f\u901a\u8fc7\u4ee3\u7801\u793a\u4f8b\u8bf4\u660e<\/strong><br \/>\n<strong>\u7b54\uff1a<\/strong><br \/>\nJava \u5185\u90e8\u7c7b\u4e3b\u8981\u6709\u56db\u79cd\u7c7b\u578b\uff1a\u6210\u5458\u5185\u90e8\u7c7b\u3001\u5c40\u90e8\u5185\u90e8\u7c7b\u3001\u533f\u540d\u5185\u90e8\u7c7b\u548c\u9759\u6001\u5185\u90e8\u7c7b\u3002<\/p>\n<ul>\n<li>\n<p><strong>\u6210\u5458\u5185\u90e8\u7c7b\uff1a<\/strong><br \/>\n\u6210\u5458\u5185\u90e8\u7c7b\u5b9a\u4e49\u5728\u5916\u90e8\u7c7b\u7684\u5185\u90e8\uff0c\u4f5c\u4e3a\u5916\u90e8\u7c7b\u7684\u4e00\u4e2a\u6210\u5458\u5b58\u5728\u3002<br \/>\n\u5b83\u53ef\u4ee5\u8bbf\u95ee\u5916\u90e8\u7c7b\u7684\u6240\u6709\u6210\u5458\uff08\u5305\u62ec\u79c1\u6709\u6210\u5458\uff09\uff0c\u521b\u5efa\u6210\u5458\u5185\u90e8\u7c7b\u5bf9\u8c61\u9700\u8981\u5148\u521b\u5efa\u5916\u90e8\u7c7b\u5bf9\u8c61\u3002<\/p>\n<pre><code class=\"language-java\">\/\/ \u5916\u90e8\u7c7b\nclass OuterClass {\n\/\/ \u5916\u90e8\u7c7b\u79c1\u6709\u5c5e\u6027\nprivate int outerData = 10;\n\n\/\/ \u6210\u5458\u5185\u90e8\u7c7b\nclass InnerClass {\n    \/\/ \u6210\u5458\u5185\u90e8\u7c7b\u65b9\u6cd5\n    void display() {\n        System.out.println(&quot;\u8bbf\u95ee\u5916\u90e8\u7c7b\u7684\u79c1\u6709\u6210\u5458: &quot; + outerData);\n    }\n}\n}\n\/\/ \u6d4b\u8bd5\u7c7b\npublic class MemberInnerClassExample {\npublic static void main(String[] args) {\n    OuterClass outer = new OuterClass();\n    OuterClass.InnerClass inner = outer.new InnerClass();\n    inner.display();\n}\n}<\/code><\/pre>\n<p><strong>\u4ee3\u7801\u89e3\u91ca<\/strong><\/p>\n<ul>\n<li>InnerClass \u662f OuterClass \u7684\u6210\u5458\u5185\u90e8\u7c7b\u3002<\/li>\n<li>InnerClass \u4e2d\u7684 display \u65b9\u6cd5\u53ef\u4ee5\u8bbf\u95ee\u5916\u90e8\u7c7b\u7684\u79c1\u6709\u6210\u5458 outerData\u3002<\/li>\n<li>\u5728 main \u65b9\u6cd5\u4e2d\uff0c\u9700\u8981\u5148\u521b\u5efa\u5916\u90e8\u7c7b\u5bf9\u8c61 outer\uff0c\u518d\u901a\u8fc7\u5916\u90e8\u7c7b\u5bf9\u8c61\u521b\u5efa\u5185\u90e8\u7c7b\u5bf9\u8c61 inner\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u5c40\u90e8\u5185\u90e8\u7c7b\uff1a<\/strong><br \/>\n\u5c40\u90e8\u5185\u90e8\u7c7b\u5b9a\u4e49\u5728\u65b9\u6cd5\u6216\u4ee3\u7801\u5757\u5185\u90e8\uff0c\u5176\u4f5c\u7528\u57df\u4ec5\u9650\u4e8e\u8be5\u65b9\u6cd5\u6216\u4ee3\u7801\u5757\u3002<br \/>\n\u5b83\u53ef\u4ee5\u8bbf\u95ee\u5916\u90e8\u7c7b\u7684\u6240\u6709\u6210\u5458\u4ee5\u53ca\u8be5\u65b9\u6cd5\u6216\u4ee3\u7801\u5757\u4e2d\u88ab final \u4fee\u9970\uff08Java 8 \u53ca\u4ee5\u540e\u4e3a\u4e8b\u5b9e\u4e0a\u7684 final\uff09\u7684\u5c40\u90e8\u53d8\u91cf\u3002<\/p>\n<pre><code class=\"language-java\">\/\/ \u5916\u90e8\u7c7b\nclass OuterClassForLocal {\n\/\/ \u5916\u90e8\u7c7b\u79c1\u6709\u5c5e\u6027\uff08\u6210\u5458\u53d8\u91cf\uff09\nprivate int outerData = 20;\n\/\/ \u5916\u90e8\u7c7b\u65b9\u6cd5\nvoid outerMethod() {\n    \/\/ \u5c40\u90e8\u53d8\u91cf\n    final int localVar = 30; \/\/ Java 8 \u53ca\u4ee5\u540e\u53ef\u4e0d\u663e\u5f0f\u58f0\u660e\u4e3a final\n\n    \/\/ \u5c40\u90e8\u5185\u90e8\u7c7b\n    class LocalInnerClass {\n        void show() {\n            System.out.println(&quot;\u5916\u90e8\u7c7b\u6570\u636e: &quot; + outerData);\n            System.out.println(&quot;\u5c40\u90e8\u53d8\u91cf: &quot; + localVar);\n        }\n    }\n    \/\/ \u521b\u5efa\u5c40\u90e8\u5185\u90e8\u7c7b\u5bf9\u8c61\n    LocalInnerClass localInner = new LocalInnerClass();\n    localInner.show();\n}\n}\n\/\/ \u6d4b\u8bd5\u7c7b\npublic class LocalInnerClassExample {\npublic static void main(String[] args) {\n    OuterClassForLocal outer = new OuterClassForLocal();\n    outer.outerMethod();\n}\n}<\/code><\/pre>\n<p><strong>\u4ee3\u7801\u89e3\u91ca<\/strong><\/p>\n<ul>\n<li><code>LocalInnerClass<\/code> \u662f\u5b9a\u4e49\u5728 <code>outerMethod<\/code> \u65b9\u6cd5\u5185\u90e8\u7684\u5c40\u90e8\u5185\u90e8\u7c7b\u3002<\/li>\n<li><code>LocalInnerClass<\/code> \u4e2d\u7684 <code>show<\/code> \u65b9\u6cd5\u53ef\u4ee5\u8bbf\u95ee\u5916\u90e8\u7c7b\u7684\u6210\u5458 <code>outerData<\/code> \u548c\u65b9\u6cd5\u4e2d\u7684\u5c40\u90e8\u53d8\u91cf <code>localVar<\/code>\u3002<\/li>\n<li>\u5c40\u90e8\u5185\u90e8\u7c7b\u53ea\u80fd\u5728\u5b9a\u4e49\u5b83\u7684\u65b9\u6cd5\u5185\u90e8\u4f7f\u7528\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u533f\u540d\u5185\u90e8\u7c7b\uff1a<\/strong><br \/>\n\u533f\u540d\u5185\u90e8\u7c7b\u6ca1\u6709\u7c7b\u540d\uff0c\u901a\u5e38\u7528\u4e8e\u521b\u5efa\u53ea\u4f7f\u7528\u4e00\u6b21\u7684\u7c7b\u5bf9\u8c61\u3002<br \/>\n\u540c\u6837\u53ef\u4ee5\u8bbf\u95ee\u5916\u90e8\u7c7b\u7684\u6240\u6709\u6210\u5458\u548c\u65b9\u6cd5\u4e2d <code>final<\/code> \u4fee\u9970\u7684\u5c40\u90e8\u53d8\u91cf\u3002<br \/>\n\u5b83\u5fc5\u987b\u7ee7\u627f\u4e00\u4e2a\u7236\u7c7b\u6216\u5b9e\u73b0\u4e00\u4e2a\u63a5\u53e3\u3002<\/p>\n<pre><code class=\"language-java\">\/\/ \u63a5\u53e3\ninterface MyInterface {\nvoid doSomething();\n}\n\/\/ \u5916\u90e8\u7c7b\npublic class AnonymousInnerClassExample {\n\/\/ \u4e3b\u65b9\u6cd5\npublic static void main(String[] args) {\n    \/\/ \u533f\u540d\u5185\u90e8\u7c7b\n    MyInterface obj = new MyInterface() {\n        @Override\n        public void doSomething() {\n            System.out.println(&quot;\u533f\u540d\u5185\u90e8\u7c7b\u5b9e\u73b0\u63a5\u53e3\u65b9\u6cd5&quot;);\n        }\n    };\n    obj.doSomething();\n}\n}<\/code><\/pre>\n<p><strong>\u4ee3\u7801\u89e3\u91ca<\/strong><\/p>\n<ul>\n<li>\u76f4\u63a5\u5728\u521b\u5efa\u5bf9\u8c61\u65f6\u5b9e\u73b0\u4e86 <code>MyInterface<\/code> \u63a5\u53e3\uff0c\u6ca1\u6709\u663e\u5f0f\u5b9a\u4e49\u7c7b\u540d\uff0c\u8fd9\u5c31\u662f\u533f\u540d\u5185\u90e8\u7c7b\u3002<\/li>\n<li>\u533f\u540d\u5185\u90e8\u7c7b\u91cd\u5199\u4e86 <code>MyInterface<\/code> \u63a5\u53e3\u7684 <code>doSomething<\/code> \u65b9\u6cd5\u3002<\/li>\n<li>\u521b\u5efa\u7684\u533f\u540d\u5185\u90e8\u7c7b\u5bf9\u8c61\u8d4b\u503c\u7ed9 <code>MyInterface<\/code> \u7c7b\u578b\u7684\u5f15\u7528 <code>obj<\/code>\uff0c\u5e76\u8c03\u7528\u5176\u65b9\u6cd5\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u9759\u6001\u5185\u90e8\u7c7b\uff1a<\/strong><br \/>\n\u9759\u6001\u5185\u90e8\u7c7b\u4f7f\u7528 static \u4fee\u9970\uff0c\u5b83\u53ea\u80fd\u8bbf\u95ee\u5916\u90e8\u7c7b\u7684\u9759\u6001\u6210\u5458\u3002<br \/>\n\u521b\u5efa\u9759\u6001\u5185\u90e8\u7c7b\u5bf9\u8c61\u4e0d\u9700\u8981\u5148\u521b\u5efa\u5916\u90e8\u7c7b\u5bf9\u8c61\u3002<\/p>\n<pre><code class=\"language-java\">\/\/ \u5916\u90e8\u7c7b\nclass OuterClassForStatic {\n\/\/\u5916\u90e8\u7c7b\u9759\u6001\u79c1\u6709\u5c5e\u6027\nprivate static int staticOuterData = 40;\n\n\/\/ \u9759\u6001\u5185\u90e8\u7c7b\nstatic class StaticInnerClass {\n    void printData() {\n        System.out.println(&quot;\u8bbf\u95ee\u5916\u90e8\u7c7b\u7684\u9759\u6001\u6210\u5458: &quot; + staticOuterData);\n    }\n}\n}\n\/\/ \u6d4b\u8bd5\u7c7b\npublic class StaticInnerClassExample {\npublic static void main(String[] args) {\n    OuterClassForStatic.StaticInnerClass staticInner = new OuterClassForStatic.StaticInnerClass();\n    staticInner.printData();\n}\n}<\/code><\/pre>\n<p><strong>\u4ee3\u7801\u89e3\u91ca<\/strong><\/p>\n<ul>\n<li><code>StaticInnerClass<\/code> \u662f\u4f7f\u7528 <code>static<\/code> \u4fee\u9970\u7684\u9759\u6001\u5185\u90e8\u7c7b\u3002<\/li>\n<li><code>StaticInnerClass<\/code> \u4e2d\u7684 <code>printData<\/code> \u65b9\u6cd5\u53ef\u4ee5\u8bbf\u95ee\u5916\u90e8\u7c7b\u7684\u9759\u6001\u6210\u5458 <code>staticOuterData<\/code>\u3002<\/li>\n<li>\u5728 <code>main<\/code> \u65b9\u6cd5\u4e2d\uff0c\u53ef\u4ee5\u76f4\u63a5\u521b\u5efa\u9759\u6001\u5185\u90e8\u7c7b\u5bf9\u8c61\uff0c\u65e0\u9700\u5148\u521b\u5efa\u5916\u90e8\u7c7b\u5bf9\u8c61\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><strong>2. \u9759\u6001\u5185\u90e8\u7c7b\u548c\u975e\u9759\u6001\u5185\u90e8\u7c7b\u5728\u521b\u5efa\u5bf9\u8c61\u65f6\u6709\u4ec0\u4e48\u533a\u522b\uff1f<\/strong><br \/>\n<strong>\u7b54\uff1a<\/strong><br \/>\n<strong>\u975e\u9759\u6001\u5185\u90e8\u7c7b\uff08\u6210\u5458\u5185\u90e8\u7c7b\u3001\u5c40\u90e8\u5185\u90e8\u7c7b\u3001\u533f\u540d\u5185\u90e8\u7c7b\uff09\uff1a<\/strong><br \/>\n\u521b\u5efa\u975e\u9759\u6001\u5185\u90e8\u7c7b\u5bf9\u8c61\u524d\uff0c\u5fc5\u987b\u5148\u521b\u5efa\u5916\u90e8\u7c7b\u5bf9\u8c61\u3002<br \/>\n\u56e0\u4e3a\u975e\u9759\u6001\u5185\u90e8\u7c7b\u9690\u5f0f\u6301\u6709\u5916\u90e8\u7c7b\u5bf9\u8c61\u7684\u5f15\u7528\uff0c\u4f9d\u8d56\u4e8e\u5916\u90e8\u7c7b\u5bf9\u8c61\u5b58\u5728\u3002<\/p>\n<p><strong>\u9759\u6001\u5185\u90e8\u7c7b\uff1a<\/strong><br \/>\n\u521b\u5efa\u9759\u6001\u5185\u90e8\u7c7b\u5bf9\u8c61\u4e0d\u9700\u8981\u5148\u521b\u5efa\u5916\u90e8\u7c7b\u5bf9\u8c61\u3002<br \/>\n\u56e0\u4e3a\u9759\u6001\u5185\u90e8\u7c7b\u4e0d\u4f9d\u8d56\u4e8e\u5916\u90e8\u7c7b\u7684\u5b9e\u4f8b\uff0c\u5b83\u53ef\u4ee5\u72ec\u7acb\u5b58\u5728\u3002<\/p>\n<p><strong>3. \u6210\u5458\u5185\u90e8\u7c7b\u3001\u5c40\u90e8\u5185\u90e8\u7c7b\u3001\u533f\u540d\u5185\u90e8\u7c7b\u3001\u9759\u6001\u5185\u90e8\u7c7b\u7ecf\u5178\u4f7f\u7528\u573a\u666f<\/strong><br \/>\n<strong>\u7b54\uff1a<\/strong><\/p>\n<ul>\n<li><strong>\u6210\u5458\u5185\u90e8\u7c7b<\/strong>\n<ul>\n<li>\u5b9e\u73b0\u591a\u91cd\u7ee7\u627f\u6548\u679c\uff1a\u5728 Java \u4e2d\u7c7b\u53ea\u80fd\u5355\u7ee7\u627f\uff0c\u4f46\u53ef\u4ee5\u901a\u8fc7\u6210\u5458\u5185\u90e8\u7c7b\u7ee7\u627f\u5176\u4ed6\u7c7b\uff0c\u5b9e\u73b0\u7c7b\u4f3c\u591a\u91cd\u7ee7\u627f\u7684\u529f\u80fd\u3002<\/li>\n<li>\u4e8b\u4ef6\u76d1\u542c\u673a\u5236\uff1a\u5728 GUI \u7f16\u7a0b\u4e2d\uff0c\u6210\u5458\u5185\u90e8\u7c7b\u53ef\u7528\u4e8e\u5b9e\u73b0\u4e8b\u4ef6\u76d1\u542c\u5668\uff0c\u65b9\u4fbf\u8bbf\u95ee\u5916\u90e8\u7c7b\u7684\u7ec4\u4ef6\u548c\u72b6\u6001\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u5c40\u90e8\u5185\u90e8\u7c7b<\/strong>\n<ul>\n<li>\u65b9\u6cd5\u5185\u90e8\u7684\u590d\u6742\u903b\u8f91\u5c01\u88c5\uff1a\u5f53\u4e00\u4e2a\u65b9\u6cd5\u4e2d\u7684\u903b\u8f91\u8f83\u4e3a\u590d\u6742\uff0c\u9700\u8981\u4e00\u4e9b\u8f85\u52a9\u7c7b\u6765\u5b8c\u6210\u7279\u5b9a\u5b50\u4efb\u52a1\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u5c40\u90e8\u5185\u90e8\u7c7b\u3002<\/li>\n<li>\u4e34\u65f6\u6570\u636e\u5904\u7406\uff1a\u5728\u67d0\u4e2a\u65b9\u6cd5\u4e2d\u9700\u8981\u5bf9\u4e00\u4e9b\u4e34\u65f6\u6570\u636e\u8fdb\u884c\u5904\u7406\uff0c\u5e76\u4e14\u8fd9\u4e9b\u5904\u7406\u903b\u8f91\u9700\u8981\u5c01\u88c5\u5728\u4e00\u4e2a\u7c7b\u4e2d\u65f6\u4f7f\u7528\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u533f\u540d\u5185\u90e8\u7c7b<\/strong>\n<ul>\n<li>\u4e8b\u4ef6\u5904\u7406\uff1a\u5728 GUI \u7f16\u7a0b\u4e2d\uff0c\u7528\u4e8e\u521b\u5efa\u4e8b\u4ef6\u76d1\u542c\u5668\uff0c\u4ee3\u7801\u7b80\u6d01\uff0c\u907f\u514d\u521b\u5efa\u5927\u91cf\u7684\u76d1\u542c\u5668\u7c7b\u3002<\/li>\n<li>\u56de\u8c03\u51fd\u6570\uff1a\u5728\u9700\u8981\u4f20\u9012\u4e00\u4e2a\u7b80\u5355\u7684\u56de\u8c03\u51fd\u6570\u65f6\u4f7f\u7528\uff0c\u4f8b\u5982\u7ebf\u7a0b\u7684 Runnable \u63a5\u53e3\u5b9e\u73b0\uff08Java8\u540e\u4f7f\u7528lambda\u8868\u8fbe\u5f0f\u66f4\u7b80\u6d01\uff09\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u9759\u6001\u5185\u90e8\u7c7b<\/strong>\n<ul>\n<li>\u6570\u636e\u7ed3\u6784\u5d4c\u5957\uff1a\u5f53\u4e00\u4e2a\u7c7b\u9700\u8981\u5305\u542b\u53e6\u4e00\u4e2a\u7d27\u5bc6\u76f8\u5173\u7684\u6570\u636e\u7ed3\u6784\u7c7b\u65f6\uff0c\u4f7f\u7528\u9759\u6001\u5185\u90e8\u7c7b\u53ef\u4ee5\u4f7f\u4ee3\u7801\u7ed3\u6784\u66f4\u6e05\u6670\u3002<\/li>\n<li>\u8f85\u52a9\u5de5\u5177\u7c7b\uff1a\u5728\u5916\u90e8\u7c7b\u4e2d\u63d0\u4f9b\u4e00\u4e9b\u8f85\u52a9\u529f\u80fd\u7684\u5de5\u5177\u7c7b\uff0c\u4f7f\u7528\u9759\u6001\u5185\u90e8\u7c7b\u53ef\u4ee5\u907f\u514d\u521b\u5efa\u4e0d\u5fc5\u8981\u7684\u5916\u90e8\u7c7b\u5b9e\u4f8b\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h1>\u516d\u3001\u679a\u4e3e\u7c7b<\/h1>\n<p><strong>1. \u4ec0\u4e48\u662f Java \u4e2d\u7684\u679a\u4e3e\u7c7b\uff0c\u5b83\u6709\u4ec0\u4e48\u7279\u70b9\uff1f<\/strong><br \/>\n<strong>\u7b54\uff1a<\/strong><br \/>\nJava \u4e2d\u7684\u679a\u4e3e\u7c7b\u662f\u4e00\u79cd\u7279\u6b8a\u7684\u7c7b\uff0c\u7528\u4e8e\u5b9a\u4e49\u4e00\u7ec4\u56fa\u5b9a\u7684\u5e38\u91cf\u3002<br \/>\n\u5b83\u7684\u7279\u70b9\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li><strong>\u5e38\u91cf\u96c6\u5408\uff1a<\/strong>\u679a\u4e3e\u7c7b\u7684\u5b9e\u4f8b\u662f\u56fa\u5b9a\u7684\uff0c\u901a\u5e38\u7528\u4e8e\u8868\u793a\u4e00\u7ec4\u6709\u9650\u7684\u3001\u9884\u5b9a\u4e49\u7684\u503c\u3002\u5982\u4e00\u5468\u7684\u4e03\u5929\u3001\u4e00\u5e74\u7684\u56db\u5b63\u7b49\u3002<\/li>\n<li><strong>\u7c7b\u578b\u5b89\u5168\uff1a<\/strong>\u679a\u4e3e\u7c7b\u578b\u53ef\u4ee5\u4fdd\u8bc1\u53d8\u91cf\u53ea\u80fd\u53d6\u679a\u4e3e\u7c7b\u4e2d\u5b9a\u4e49\u7684\u503c\uff0c\u907f\u514d\u4e86\u4f7f\u7528\u666e\u901a\u5e38\u91cf\u53ef\u80fd\u5e26\u6765\u7684\u7c7b\u578b\u4e0d\u5339\u914d\u95ee\u9898\u3002<\/li>\n<li><strong>\u5355\u4f8b\u6a21\u5f0f\u5b9e\u73b0\uff1a<\/strong>\u679a\u4e3e\u7c7b\u5929\u7136\u652f\u6301\u5355\u4f8b\u6a21\u5f0f\uff0c\u6bcf\u4e2a\u679a\u4e3e\u5e38\u91cf\u5728 JVM \u4e2d\u662f\u552f\u4e00\u7684\u5b9e\u4f8b\u3002<\/li>\n<li><strong>\u53ef\u6dfb\u52a0\u65b9\u6cd5\u548c\u5c5e\u6027\uff1a<\/strong>\u679a\u4e3e\u7c7b\u53ef\u4ee5\u50cf\u666e\u901a\u7c7b\u4e00\u6837\u62e5\u6709\u6210\u5458\u53d8\u91cf\u3001\u65b9\u6cd5\u7b49\uff0c\u5e76\u4e14\u53ef\u4ee5\u4e3a\u6bcf\u4e2a\u679a\u4e3e\u5e38\u91cf\u63d0\u4f9b\u4e0d\u540c\u7684\u884c\u4e3a\u3002<\/li>\n<\/ul>\n<p><strong>2. \u5982\u4f55\u5728\u679a\u4e3e\u7c7b\u4e2d\u5b9a\u4e49\u6784\u9020\u65b9\u6cd5\u3001\u6210\u5458\u53d8\u91cf\u548c\u65b9\u6cd5\uff1f\u8bf7\u4e3e\u4f8b\u8bf4\u660e\u3002<\/strong><br \/>\n<strong>\u7b54\uff1a<\/strong><br \/>\n\u679a\u4e3e\u7c7b\u53ef\u4ee5\u5b9a\u4e49\u6784\u9020\u65b9\u6cd5\u3001\u6210\u5458\u53d8\u91cf\u548c\u65b9\u6cd5\u3002<br \/>\n\u6784\u9020\u65b9\u6cd5\u5fc5\u987b\u662f\u79c1\u6709\u7684\uff0c\u56e0\u4e3a\u679a\u4e3e\u5e38\u91cf\u7684\u5b9e\u4f8b\u662f\u56fa\u5b9a\u7684\uff0c\u4e0d\u5141\u8bb8\u5916\u90e8\u521b\u5efa\u65b0\u7684\u5b9e\u4f8b\u3002<br \/>\n\u4f8b\u5982\uff1a<\/p>\n<pre><code class=\"language-java\">\/\/ \u679a\u4e3e\u7c7b\uff1a\u5b63\u8282\nenum Season {\n    \/\/ \u679a\u4e3e\u5e38\u91cf\uff0c\u8c03\u7528\u6784\u9020\u65b9\u6cd5\u8fdb\u884c\u521d\u59cb\u5316\n    SPRING(&quot;\u6625\u5929&quot;, &quot;\u6e29\u6696&quot;),\n    SUMMER(&quot;\u590f\u5929&quot;, &quot;\u708e\u70ed&quot;),\n    AUTUMN(&quot;\u79cb\u5929&quot;, &quot;\u51c9\u723d&quot;),\n    WINTER(&quot;\u51ac\u5929&quot;, &quot;\u5bd2\u51b7&quot;);\n\n    \/\/ \u6210\u5458\u53d8\u91cf\n    private final String name;\n    private final String description;\n\n    \/\/ \u6784\u9020\u65b9\u6cd5\uff0c\u5fc5\u987b\u662f\u79c1\u6709\n    private Season(String name, String description) {\n        this.name = name;\n        this.description = description;\n    }\n\n    \/\/ \u83b7\u53d6\u540d\u79f0\u7684\u65b9\u6cd5\n    public String getName() {\n        return name;\n    }\n\n    \/\/ \u83b7\u53d6\u63cf\u8ff0\u7684\u65b9\u6cd5\n    public String getDescription() {\n        return description;\n    }\n}\n\/\/ \u6d4b\u8bd5\u7c7b\npublic class EnumExample {\n    public static void main(String[] args) {\n        Season spring = Season.SPRING;\n        System.out.println(spring.getName() + &quot;\uff1a&quot; + spring.getDescription());\n    }\n}<\/code><\/pre>\n<p><strong>3. \u679a\u4e3e\u7c7b\u5728 switch \u8bed\u53e5\u4e2d\u7684\u4f7f\u7528\u6709\u4ec0\u4e48\u4f18\u52bf\uff1f<\/strong><br \/>\n<strong>\u7b54\uff1a<\/strong><br \/>\n\u679a\u4e3e\u7c7b\u5728 switch \u8bed\u53e5\u4e2d\u4f7f\u7528\u5177\u6709\u4ee5\u4e0b\u4f18\u52bf\uff1a<\/p>\n<ul>\n<li><strong>\u7c7b\u578b\u5b89\u5168\uff1a<\/strong>switch \u8bed\u53e5\u7684\u8868\u8fbe\u5f0f\u7c7b\u578b\u4e3a\u679a\u4e3e\u7c7b\u578b\u65f6\uff0ccase \u6807\u7b7e\u53ea\u80fd\u662f\u8be5\u679a\u4e3e\u7c7b\u7684\u5e38\u91cf\uff0c\u7f16\u8bd1\u5668\u4f1a\u8fdb\u884c\u7c7b\u578b\u68c0\u67e5\uff0c\u907f\u514d\u4e86\u4f7f\u7528\u666e\u901a\u6574\u6570\u6216\u5b57\u7b26\u4e32\u5e38\u91cf\u53ef\u80fd\u51fa\u73b0\u7684\u62fc\u5199\u9519\u8bef\u7b49\u95ee\u9898\u3002<\/li>\n<li><strong>\u4ee3\u7801\u53ef\u8bfb\u6027\u9ad8\uff1a<\/strong>\u4f7f\u7528\u679a\u4e3e\u5e38\u91cf\u4f5c\u4e3a case \u6807\u7b7e\uff0c\u4ee3\u7801\u66f4\u5177\u53ef\u8bfb\u6027\uff0c\u80fd\u591f\u6e05\u6670\u5730\u8868\u8fbe\u6bcf\u4e2a\u5206\u652f\u7684\u542b\u4e49\u3002<\/li>\n<li><strong>\u7ef4\u62a4\u65b9\u4fbf\uff1a<\/strong>\u5f53\u679a\u4e3e\u7c7b\u7684\u5e38\u91cf\u53d1\u751f\u53d8\u5316\u65f6\uff0c\u7f16\u8bd1\u5668\u4f1a\u63d0\u793a switch \u8bed\u53e5\u4e2d\u53ef\u80fd\u9700\u8981\u66f4\u65b0\u7684\u5730\u65b9\uff0c\u4fbf\u4e8e\u4ee3\u7801\u7684\u7ef4\u62a4\u548c\u6269\u5c55\u3002\n<pre><code class=\"language-java\">\/\/ \u679a\u4e3e\u7c7b\uff1a\u5468\u5929\nenum Weekday {\nMONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY\n}\n\/\/ \u6d4b\u8bd5\u7c7b\npublic class EnumSwitchExample {\npublic static void main(String[] args) {\n    \/\/ \u6b64\u5904today\u6a21\u62df\u5916\u90e8\u53c2\u6570\u7684\u503c\n    Weekday today = Weekday.MONDAY;\n    switch (today) {\n        case MONDAY:\n            System.out.println(&quot;\u4eca\u5929\u662f\u5468\u4e00\uff0c\u5f00\u59cb\u65b0\u7684\u4e00\u5468&quot;);\n            break;\n        case TUESDAY:\n            System.out.println(&quot;\u4eca\u5929\u662f\u5468\u4e8c\uff0c\u7ee7\u7eed\u52aa\u529b&quot;);\n            break;\n        \/\/ \u5176\u4ed6 case \u5206\u652f...\n        default:\n            System.out.println(&quot;\u672a\u77e5\u7684\u661f\u671f&quot;);\n    }\n}\n}<\/code><\/pre>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u9762\u5411\u5bf9\u8c61\u3001\u7c7b\u4e0e\u5bf9\u8c61\u3001\u91cd\u8f7d\u4e0e\u91cd\u5199\u3001\u5c01\u88c5\u3001\u7ee7\u627f\u3001\u591a\u6001\u3001\u62bd\u8c61\u7c7b\u4e0e\u63a5\u53e3\u3001\u5185\u90e8\u7c7b\u3001\u679a\u4e3e\u7c7b<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[58,84],"tags":[86,87,85],"class_list":{"0":"post-1249","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"hentry","6":"category-java_base","7":"category-interview","8":"tag-java","10":"tag-85"},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u9762\u8bd5\u7b14\u8bb002-Java\u57fa\u7840\uff08\u4e8c\uff09\uff1a\u9762\u5411\u5bf9\u8c61 | \u9676\u5176\u7684\u4e2a\u4eba\u535a\u5ba2<\/title>\n<meta name=\"description\" content=\"\u9762\u5411\u5bf9\u8c61\u3001\u7c7b\u4e0e\u5bf9\u8c61\u3001\u91cd\u8f7d\u4e0e\u91cd\u5199\u3001\u5c01\u88c5\u3001\u7ee7\u627f\u3001\u591a\u6001\u3001\u62bd\u8c61\u7c7b\u4e0e\u63a5\u53e3\u3001\u5185\u90e8\u7c7b\u3001\u679a\u4e3e\u7c7b\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.tqazy.com\/?p=1249\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u9762\u8bd5\u7b14\u8bb002-Java\u57fa\u7840\uff08\u4e8c\uff09\uff1a\u9762\u5411\u5bf9\u8c61 | \u9676\u5176\u7684\u4e2a\u4eba\u535a\u5ba2\" \/>\n<meta property=\"og:description\" content=\"\u9762\u5411\u5bf9\u8c61\u3001\u7c7b\u4e0e\u5bf9\u8c61\u3001\u91cd\u8f7d\u4e0e\u91cd\u5199\u3001\u5c01\u88c5\u3001\u7ee7\u627f\u3001\u591a\u6001\u3001\u62bd\u8c61\u7c7b\u4e0e\u63a5\u53e3\u3001\u5185\u90e8\u7c7b\u3001\u679a\u4e3e\u7c7b\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.tqazy.com\/?p=1249\" \/>\n<meta property=\"og:site_name\" content=\"\u9676\u5176\u7684\u4e2a\u4eba\u535a\u5ba2\" \/>\n<meta property=\"article:published_time\" content=\"2025-02-24T05:45:49+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-02-24T12:25:59+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/oss.tqazy.com\/wordpress\/autoFile\/2024\/05\/20240530090910445.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1920\" \/>\n\t<meta property=\"og:image:height\" content=\"1080\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"\u9676\u5176\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u9676\u5176\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.tqazy.com\/?p=1249#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.tqazy.com\/?p=1249\"},\"author\":{\"name\":\"\u9676\u5176\",\"@id\":\"https:\/\/www.tqazy.com\/#\/schema\/person\/b2e89d56e70f15c261012417c5ef2c4e\"},\"headline\":\"\u9762\u8bd5\u7b14\u8bb002-Java\u57fa\u7840\uff08\u4e8c\uff09\uff1a\u9762\u5411\u5bf9\u8c61\",\"datePublished\":\"2025-02-24T05:45:49+00:00\",\"dateModified\":\"2025-02-24T12:25:59+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.tqazy.com\/?p=1249\"},\"wordCount\":107,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\/\/www.tqazy.com\/#\/schema\/person\/b2e89d56e70f15c261012417c5ef2c4e\"},\"keywords\":[\"Java\",\"Java\u57fa\u7840\",\"\u9762\u8bd5\u516b\u80a1\"],\"articleSection\":[\"Java\u57fa\u7840\",\"\u9762\u8bd5\u516b\u80a1\"],\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.tqazy.com\/?p=1249#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.tqazy.com\/?p=1249\",\"url\":\"https:\/\/www.tqazy.com\/?p=1249\",\"name\":\"\u9762\u8bd5\u7b14\u8bb002-Java\u57fa\u7840\uff08\u4e8c\uff09\uff1a\u9762\u5411\u5bf9\u8c61 | \u9676\u5176\u7684\u4e2a\u4eba\u535a\u5ba2\",\"isPartOf\":{\"@id\":\"https:\/\/www.tqazy.com\/#website\"},\"datePublished\":\"2025-02-24T05:45:49+00:00\",\"dateModified\":\"2025-02-24T12:25:59+00:00\",\"description\":\"\u9762\u5411\u5bf9\u8c61\u3001\u7c7b\u4e0e\u5bf9\u8c61\u3001\u91cd\u8f7d\u4e0e\u91cd\u5199\u3001\u5c01\u88c5\u3001\u7ee7\u627f\u3001\u591a\u6001\u3001\u62bd\u8c61\u7c7b\u4e0e\u63a5\u53e3\u3001\u5185\u90e8\u7c7b\u3001\u679a\u4e3e\u7c7b\",\"breadcrumb\":{\"@id\":\"https:\/\/www.tqazy.com\/?p=1249#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.tqazy.com\/?p=1249\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.tqazy.com\/?p=1249#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.tqazy.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u9762\u8bd5\u7b14\u8bb002-Java\u57fa\u7840\uff08\u4e8c\uff09\uff1a\u9762\u5411\u5bf9\u8c61\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.tqazy.com\/#website\",\"url\":\"https:\/\/www.tqazy.com\/\",\"name\":\"\u9676\u5176\u7684\u4e2a\u4eba\u535a\u5ba2\",\"description\":\"\u5f53\u4e0b\uff0c\u5373\u662f\u672a\u6765\",\"publisher\":{\"@id\":\"https:\/\/www.tqazy.com\/#\/schema\/person\/b2e89d56e70f15c261012417c5ef2c4e\"},\"alternateName\":\"TaoQi's Blog\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.tqazy.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"zh-Hans\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/www.tqazy.com\/#\/schema\/person\/b2e89d56e70f15c261012417c5ef2c4e\",\"name\":\"\u9676\u5176\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.tqazy.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/oss.tqazy.com\/wordpress\/autoFile\/2024\/06\/20240604021741672.jpg\",\"contentUrl\":\"https:\/\/oss.tqazy.com\/wordpress\/autoFile\/2024\/06\/20240604021741672.jpg\",\"width\":940,\"height\":940,\"caption\":\"\u9676\u5176\"},\"logo\":{\"@id\":\"https:\/\/www.tqazy.com\/#\/schema\/person\/image\/\"},\"description\":\"\u4e00\u4e2a\u5f88\u61d2\u7684\u7a0b\u5e8f\u5458\",\"sameAs\":[\"https:\/\/www.tqazy.com\"],\"url\":\"https:\/\/www.tqazy.com\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u9762\u8bd5\u7b14\u8bb002-Java\u57fa\u7840\uff08\u4e8c\uff09\uff1a\u9762\u5411\u5bf9\u8c61 | \u9676\u5176\u7684\u4e2a\u4eba\u535a\u5ba2","description":"\u9762\u5411\u5bf9\u8c61\u3001\u7c7b\u4e0e\u5bf9\u8c61\u3001\u91cd\u8f7d\u4e0e\u91cd\u5199\u3001\u5c01\u88c5\u3001\u7ee7\u627f\u3001\u591a\u6001\u3001\u62bd\u8c61\u7c7b\u4e0e\u63a5\u53e3\u3001\u5185\u90e8\u7c7b\u3001\u679a\u4e3e\u7c7b","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.tqazy.com\/?p=1249","og_locale":"zh_CN","og_type":"article","og_title":"\u9762\u8bd5\u7b14\u8bb002-Java\u57fa\u7840\uff08\u4e8c\uff09\uff1a\u9762\u5411\u5bf9\u8c61 | \u9676\u5176\u7684\u4e2a\u4eba\u535a\u5ba2","og_description":"\u9762\u5411\u5bf9\u8c61\u3001\u7c7b\u4e0e\u5bf9\u8c61\u3001\u91cd\u8f7d\u4e0e\u91cd\u5199\u3001\u5c01\u88c5\u3001\u7ee7\u627f\u3001\u591a\u6001\u3001\u62bd\u8c61\u7c7b\u4e0e\u63a5\u53e3\u3001\u5185\u90e8\u7c7b\u3001\u679a\u4e3e\u7c7b","og_url":"https:\/\/www.tqazy.com\/?p=1249","og_site_name":"\u9676\u5176\u7684\u4e2a\u4eba\u535a\u5ba2","article_published_time":"2025-02-24T05:45:49+00:00","article_modified_time":"2025-02-24T12:25:59+00:00","og_image":[{"width":1920,"height":1080,"url":"https:\/\/oss.tqazy.com\/wordpress\/autoFile\/2024\/05\/20240530090910445.jpg","type":"image\/jpeg"}],"author":"\u9676\u5176","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"\u9676\u5176","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.tqazy.com\/?p=1249#article","isPartOf":{"@id":"https:\/\/www.tqazy.com\/?p=1249"},"author":{"name":"\u9676\u5176","@id":"https:\/\/www.tqazy.com\/#\/schema\/person\/b2e89d56e70f15c261012417c5ef2c4e"},"headline":"\u9762\u8bd5\u7b14\u8bb002-Java\u57fa\u7840\uff08\u4e8c\uff09\uff1a\u9762\u5411\u5bf9\u8c61","datePublished":"2025-02-24T05:45:49+00:00","dateModified":"2025-02-24T12:25:59+00:00","mainEntityOfPage":{"@id":"https:\/\/www.tqazy.com\/?p=1249"},"wordCount":107,"commentCount":1,"publisher":{"@id":"https:\/\/www.tqazy.com\/#\/schema\/person\/b2e89d56e70f15c261012417c5ef2c4e"},"keywords":["Java","Java\u57fa\u7840","\u9762\u8bd5\u516b\u80a1"],"articleSection":["Java\u57fa\u7840","\u9762\u8bd5\u516b\u80a1"],"inLanguage":"zh-Hans","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.tqazy.com\/?p=1249#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.tqazy.com\/?p=1249","url":"https:\/\/www.tqazy.com\/?p=1249","name":"\u9762\u8bd5\u7b14\u8bb002-Java\u57fa\u7840\uff08\u4e8c\uff09\uff1a\u9762\u5411\u5bf9\u8c61 | \u9676\u5176\u7684\u4e2a\u4eba\u535a\u5ba2","isPartOf":{"@id":"https:\/\/www.tqazy.com\/#website"},"datePublished":"2025-02-24T05:45:49+00:00","dateModified":"2025-02-24T12:25:59+00:00","description":"\u9762\u5411\u5bf9\u8c61\u3001\u7c7b\u4e0e\u5bf9\u8c61\u3001\u91cd\u8f7d\u4e0e\u91cd\u5199\u3001\u5c01\u88c5\u3001\u7ee7\u627f\u3001\u591a\u6001\u3001\u62bd\u8c61\u7c7b\u4e0e\u63a5\u53e3\u3001\u5185\u90e8\u7c7b\u3001\u679a\u4e3e\u7c7b","breadcrumb":{"@id":"https:\/\/www.tqazy.com\/?p=1249#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.tqazy.com\/?p=1249"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.tqazy.com\/?p=1249#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.tqazy.com\/"},{"@type":"ListItem","position":2,"name":"\u9762\u8bd5\u7b14\u8bb002-Java\u57fa\u7840\uff08\u4e8c\uff09\uff1a\u9762\u5411\u5bf9\u8c61"}]},{"@type":"WebSite","@id":"https:\/\/www.tqazy.com\/#website","url":"https:\/\/www.tqazy.com\/","name":"\u9676\u5176\u7684\u4e2a\u4eba\u535a\u5ba2","description":"\u5f53\u4e0b\uff0c\u5373\u662f\u672a\u6765","publisher":{"@id":"https:\/\/www.tqazy.com\/#\/schema\/person\/b2e89d56e70f15c261012417c5ef2c4e"},"alternateName":"TaoQi's Blog","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.tqazy.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"zh-Hans"},{"@type":["Person","Organization"],"@id":"https:\/\/www.tqazy.com\/#\/schema\/person\/b2e89d56e70f15c261012417c5ef2c4e","name":"\u9676\u5176","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.tqazy.com\/#\/schema\/person\/image\/","url":"https:\/\/oss.tqazy.com\/wordpress\/autoFile\/2024\/06\/20240604021741672.jpg","contentUrl":"https:\/\/oss.tqazy.com\/wordpress\/autoFile\/2024\/06\/20240604021741672.jpg","width":940,"height":940,"caption":"\u9676\u5176"},"logo":{"@id":"https:\/\/www.tqazy.com\/#\/schema\/person\/image\/"},"description":"\u4e00\u4e2a\u5f88\u61d2\u7684\u7a0b\u5e8f\u5458","sameAs":["https:\/\/www.tqazy.com"],"url":"https:\/\/www.tqazy.com\/?author=1"}]}},"_links":{"self":[{"href":"https:\/\/www.tqazy.com\/index.php?rest_route=\/wp\/v2\/posts\/1249","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tqazy.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tqazy.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tqazy.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tqazy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1249"}],"version-history":[{"count":22,"href":"https:\/\/www.tqazy.com\/index.php?rest_route=\/wp\/v2\/posts\/1249\/revisions"}],"predecessor-version":[{"id":1309,"href":"https:\/\/www.tqazy.com\/index.php?rest_route=\/wp\/v2\/posts\/1249\/revisions\/1309"}],"wp:attachment":[{"href":"https:\/\/www.tqazy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1249"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tqazy.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1249"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tqazy.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1249"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}