{"id":76190,"date":"2026-02-21T22:49:08","date_gmt":"2026-02-21T14:49:08","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/76190.html"},"modified":"2026-02-21T22:49:08","modified_gmt":"2026-02-21T14:49:08","slug":"%e6%b3%a8%e6%84%8f%ef%bc%9a%e5%a4%9a%e6%80%81%e4%b8%8d%e6%98%af%e5%a4%9a%e5%8f%98%e6%80%81","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/76190.html","title":{"rendered":"\u6ce8\u610f\uff1a\u591a\u6001\u4e0d\u662f\u201c\u591a\u53d8\u6001\u201d"},"content":{"rendered":"<h3 style=\"background-color:transparent\">1&#xff0c;\u4ec0\u4e48\u662f\u591a\u6001&#xff1f;<\/h3>\n<p><span style=\"color:#333333\">\u662f\u591a\u79cd\u5f62\u6001&#xff0c;<\/span><span style=\"color:#333333\">\u5177\u4f53\u70b9\u5c31\u662f\u53bb\u5b8c\u6210\u67d0\u4e2a\u884c\u4e3a&#xff0c;\u5f53\u4e0d\u540c\u7684\u5bf9\u8c61\u53bb\u5b8c\u6210\u65f6\u4f1a\u4ea7\u751f\u51fa\u4e0d\u540c \u7684\u72b6 <\/span><\/p>\n<p>\u6001&#xff0c;\u6bd4\u5982&#xff1a;\u90fd\u662f\u5403\u996d&#xff0c;\u9e1f\u5403\u9e1f\u7cae&#xff0c;\u72d7\u5403\u72d7\u7cae&#xff0c;\u4eba\u5403\u996d&#8230;,<\/p>\n<h3>2&#xff0c;\u4e3a\u4ec0\u4e48\u6709\u591a\u6001&#xff1f;<\/h3>\n<p>\u4ece\u4e00\u4e2a\u521d\u59cb\u8005\u7684\u89d2\u5ea6\u53bb\u770b&#xff0c;\u5c31\u662f\u4e3a\u4e86\u65b9\u4fbf&#xff0c;\u4e0b\u9762\u4f1a\u7528\u4ee3\u7801\u6765\u8bf4\u660e\u3002<\/p>\n<h3><span style=\"color:#333333\">3&#xff0c;\u591a\u6001\u5b9e\u73b0\u6761\u4ef6<\/span><\/h3>\n<p><span style=\"color:#333333\">1. <\/span><span style=\"color:#333333\">\u5fc5\u987b\u5728\u7ee7\u627f\u4f53\u7cfb\u4e0b <\/span><\/p>\n<p><span style=\"color:#333333\">2. <\/span><span style=\"color:#333333\">\u5b50\u7c7b\u5fc5\u987b\u8981\u5bf9\u7236\u7c7b\u4e2d\u65b9\u6cd5\u8fdb\u884c<\/span><span style=\"color:#fe2c24\">\u91cd\u5199 <\/span><\/p>\n<p><span style=\"color:#333333\">3. <\/span><span style=\"color:#333333\">\u901a\u8fc7\u7236\u7c7b\u7684\u5f15\u7528\u8c03\u7528\u91cd\u5199\u7684\u65b9\u6cd5<\/span><\/p>\n<p><span style=\"color:#333333\">\u6ce8\u610f&#xff1a;\u591a\u6001\u4f53\u73b0&#xff1a;\u5728\u4ee3\u7801\u8fd0\u884c\u65f6&#xff0c;\u5f53\u4f20\u9012\u4e0d\u540c\u7c7b\u5bf9\u8c61\u65f6&#xff0c;\u4f1a\u8c03\u7528\u5bf9\u5e94\u7c7b\u4e2d\u7684\u65b9\u6cd5\u3002<\/span><\/p>\n<p>\u200b<br \/>\npublic class Animal {<br \/>\nString name;<br \/>\nint age;<br \/>\npublic Animal(String name, int age){<br \/>\nthis.name &#061; name;<br \/>\nthis.age &#061; age;<br \/>\n}<br \/>\npublic void eat(){<br \/>\nSystem.out.println(name &#043; &#034;\u5403\u4e1c\u897f&#034;);<br \/>\n}<br \/>\n}<br \/>\npublic class Cat extends Animal{<br \/>\npublic Cat(String name, int age){<br \/>\nsuper(name, age);<br \/>\n}<br \/>\n&#064;Override<br \/>\npublic void eat(){<br \/>\nSystem.out.println(name&#043;&#034;\u5403\u9c7c\u9975~~~&#034;);<br \/>\n}<br \/>\n}<br \/>\npublic class Dog extends Animal {<br \/>\npublic Dog(String name, int age){<br \/>\nsuper(name, age);<br \/>\n}<br \/>\n&#064;Override<br \/>\npublic void eat(){<br \/>\nSystem.out.println(name&#043;&#034;\u5403\u72d7\u7cae~~~&#034;);<br \/>\n}<br \/>\n}<\/p>\n<p>\u200b<\/p>\n<p>public class TestAnimal {<br \/>\npublic static void eat(Animal a){<br \/>\na.eat();<br \/>\n}<br \/>\npublic static void main(String[] args) {<br \/>\nCat cat &#061; new Cat(&#034;\u5c0f\u732b&#034;,2);<br \/>\nDog dog &#061; new Dog(&#034;\u5c0f\u72d7&#034;, 1);<br \/>\neat(cat);<br \/>\neat(dog);<br \/>\n}<br \/>\n}<\/p>\n<p>\/\/ \u5bf9\u4e8eeat\u65b9\u6cd5&#xff0c;\u7f16\u8bd1\u5668\u5728\u7f16\u8bd1\u4ee3\u7801\u65f6&#xff0c;\u5e76\u4e0d\u77e5\u9053\u8981\u8c03\u7528Dog \u8fd8\u662f Cat \u4e2deat\u7684\u65b9\u6cd5<br \/>\n\/\/ \u7b49\u7a0b\u5e8f\u8fd0\u884c\u8d77\u6765\u540e&#xff0c;\u5f62\u53c2a\u5f15\u7528\u7684\u5177\u4f53\u5bf9\u8c61\u786e\u5b9a\u540e&#xff0c;\u624d\u77e5\u9053\u8c03\u7528\u90a3\u4e2a\u65b9\u6cd5<br \/>\n\/\/ \u6ce8\u610f&#xff1a;\u6b64\u5904\u7684\u5f62\u53c2\u7c7b\u578b\u5fc5\u987b\u65f6\u7236\u7c7b\u7c7b\u578b\u624d\u53ef\u4ee5<\/p>\n<p>\u5982\u679c\u6ca1\u6709\u4f7f\u7528\u591a\u6001&#xff0c;\u6309\u7167\u4ee5\u524d\u7684\u5199\u6cd5\u5c31\u50cf\u4e0b\u9762\u4ee3\u7801&#xff0c;\u53ea\u80fd\u8bf4\u5404\u6709\u5343\u79cb<\/p>\n<p>class Test{<br \/>\n    public static void main(String[] args) {<br \/>\n        Cat cat1&#061;new Cat(&#034;\u5c0f\u732b&#034;,1);<br \/>\n        cat1.eat();<br \/>\n        Dog dog1&#061;new Dog(&#034;\u5c0f\u72d7&#034;,2);<br \/>\n        dog1.eat();<br \/>\n    }<br \/>\n}<\/p>\n<h3><span style=\"color:#333333\">4&#xff0c;\u4ec0\u4e48\u662f\u91cd\u5199&#xff1f;<\/span><\/h3>\n<p><span style=\"color:#333333\">\u91cd\u5199\u662f\u5b50\u7c7b\u5bf9\u5df2\u7ecf\u5b58\u5728\u7684\u7236\u7c7b\u7684\u975e\u9759\u6001\u3001\u975e<\/span><span style=\"color:#333333\">private<\/span><span style=\"color:#333333\">\u4fee\u9970&#xff0c;\u975e<\/span><span style=\"color:#333333\">final<\/span><span style=\"color:#333333\">\u4fee\u9970&#xff0c;\u975e\u6784\u9020\u65b9\u6cd5\u7b49\u7684\u5b9e\u73b0\u8fc7\u7a0b <\/span><\/p>\n<p><span style=\"color:#333333\">\u8fdb\u884c\u91cd\u65b0\u7f16\u5199\u3002\u4e5f\u5c31\u662f\u8bf4\u5b50\u7c7b\u80fd\u591f\u6839\u636e\u9700\u8981\u901a\u8fc7\u91cd\u5199\u6765\u5b9e\u73b0\u7236\u7c7b\u7684\u65b9\u6cd5\u3002<\/span><\/p>\n<h3>5&#xff0c;\u91cd\u5199\u89c4\u5219<\/h3>\n<h4>1. \u65b9\u6cd5\u7b7e\u540d\u5fc5\u987b\u5b8c\u5168\u4e00\u81f4<\/h4>\n<ul>\n<li>\u65b9\u6cd5\u540d\u548c\u53c2\u6570\u5217\u8868&#xff08;\u53c2\u6570\u6570\u91cf\u3001\u7c7b\u578b\u3001\u987a\u5e8f&#xff09;\u5fc5\u987b\u4e0e\u7236\u7c7b\u65b9\u6cd5\u5b8c\u5168\u76f8\u540c\u3002\n<ul>\n<li>\n<p>\u00a0\u9519\u8bef\u793a\u4f8b&#xff1a;\u7236\u7c7b\u65b9\u6cd5 void show&#xff08;int a&#xff09;&#xff0c;\u5b50\u7c7b\u5199\u6210\u00a0void show&#xff08;String a&#xff09;&#xff08;\u53c2\u6570\u7c7b\u578b\u4e0d\u540c&#xff0c;\u5c5e\u4e8e\u91cd\u8f7d\u800c\u975e\u91cd\u5199&#xff09;\u3002<\/p>\n<\/li>\n<li>\u00a0\u6b63\u786e\u793a\u4f8b&#xff1a;\u7236\u7c7b int add<font face=\"monospace\">(int x,int y)<\/font>&#xff0c;\u5b50\u7c7b\u91cd\u5199\u65f6\u4fdd\u6301\u00a0 int add(int x, int y)\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h4>2. \u8bbf\u95ee\u6743\u9650\u4e0d\u80fd\u66f4\u4e25\u683c<\/h4>\n<p>\u5b50\u7c7b\u91cd\u5199\u65b9\u6cd5\u7684\u8bbf\u95ee\u6743\u9650\u5fc5\u987b\u5927\u4e8e\u7b49\u4e8e\u7236\u7c7b\u65b9\u6cd5\u7684\u6743\u9650&#xff1a;<\/p>\n<ul>\n<li>\u7236\u7c7b\u65b9\u6cd5\u4e3a\u00a0public\u00a0\u2192 \u5b50\u7c7b\u53ea\u80fd\u662f\u00a0public&#xff08;\u4e0d\u80fd\u662f\u00a0protected\u00a0\u6216\u00a0private&#xff09;\u3002<\/li>\n<li>\u7236\u7c7b\u65b9\u6cd5\u4e3a\u00a0protected\u00a0\u2192 \u5b50\u7c7b\u53ef\u4ee5\u662f\u00a0protected\u00a0\u6216\u00a0public\u3002<\/li>\n<li>\u00a0\u9519\u8bef\u793a\u4f8b&#xff1a;\u7236\u7c7b\u00a0protected void test()&#xff0c;\u5b50\u7c7b\u5199\u6210\u00a0private void test()&#xff08;\u6743\u9650\u66f4\u4e25\u683c&#xff09;\u3002<\/li>\n<\/ul>\n<h4>3. \u8fd4\u56de\u503c\u7c7b\u578b\u9700\u6ee1\u8db3\u201c\u534f\u53d8\u201d<\/h4>\n<ul>\n<li>JDK 8\u53ca\u4e4b\u540e&#xff1a;\u5141\u8bb8\u8fd4\u56de\u7236\u7c7b\u8fd4\u56de\u503c\u7684\u5b50\u7c7b\u7c7b\u578b&#xff08;\u534f\u53d8\u8fd4\u56de&#xff09;\u3002\n<ul>\n<li>\u793a\u4f8b&#xff1a;\u7236\u7c7b\u65b9\u6cd5\u00a0Number getValue()&#xff0c;\u5b50\u7c7b\u53ef\u91cd\u5199\u4e3a\u00a0Integer getValue()&#xff08;Integer\u00a0\u662f\u00a0Number\u00a0\u7684\u5b50\u7c7b&#xff09;\u3002<\/li>\n<li>\u5728\u66f4\u65e9\u7684\u7f16\u8bd1\u5668\u4e2d&#xff0c;\u5f3a\u5236\u8981\u6c42\u540d\u5b57\u76f8\u540c\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h4>4. \u5f02\u5e38\u58f0\u660e\u4e0d\u80fd\u6269\u5927\u8303\u56f4<\/h4>\n<p>\u5b50\u7c7b\u91cd\u5199\u65b9\u6cd5\u629b\u51fa\u7684\u5f02\u5e38\u4e0d\u80fd\u6bd4\u7236\u7c7b\u65b9\u6cd5\u66f4\u5bbd\u6cdb<\/p>\n<p><span style=\"color:#333333\">\u4f8b\u5982&#xff1a;\u5982\u679c\u7236\u7c7b\u65b9\u6cd5\u88ab<\/span><span style=\"color:#333333\">public<\/span><span style=\"color:#333333\">\u4fee\u9970&#xff0c;\u5219\u5b50\u7c7b\u4e2d\u91cd\u5199\u8be5\u65b9 \u6cd5\u5c31\u4e0d\u80fd\u58f0\u660e\u4e3a protected<\/span><\/p>\n<p>5. \u7279\u6b8a\u4fee\u9970\u7b26\u7684\u9650\u5236<\/p>\n<ul>\n<li>static\u00a0\u65b9\u6cd5\u4e0d\u80fd\u91cd\u5199<\/li>\n<li>final\u00a0\u65b9\u6cd5\u4e0d\u80fd\u91cd\u5199<\/li>\n<li>private\u00a0\u65b9\u6cd5\u4e0d\u80fd\u91cd\u5199<\/li>\n<\/ul>\n<h3 style=\"background-color:transparent\">6&#xff0c;\u52a8\u6001\u7ed1\u5b9a<\/h3>\n<p>\u5728\u7f16\u8bd1\u7684\u65f6\u5019\u8fd8\u4e0d\u80fd\u786e\u5b9a\u662f\u8c01\u8c03\u7528\u4e86\u65b9\u6cd5&#xff0c;\u5728\u8fd0\u884c\u7684\u65f6\u5019\u624d\u77e5\u9053\u3002\u5982\u4e0b\u4ee3\u7801&#xff0c;\u5728\u7f16\u8bd1\u7684\u65f6\u5019\u8fd8\u4e0d\u77e5\u9053\u662f\u732b&#xff08;cat&#xff09;\u8fd8\u662f\u72d7&#xff08;dog&#xff09;\u8c03\u7528\u4e86\u4ee3\u7801&#xff0c;\u5230\u8fd0\u884c\u7684\u65f6\u5019\u624d\u77e5\u9053<\/p>\n<p>public class TestAnimal {<br \/>\npublic static void eat(Animal a){<br \/>\na.eat();<br \/>\n}<br \/>\npublic static void main(String[] args) {<br \/>\nCat cat &#061; new Cat(&#034;\u5c0f\u732b&#034;,2);<br \/>\nDog dog &#061; new Dog(&#034;\u5c0f\u72d7&#034;, 1);<br \/>\neat(cat);<br \/>\neat(dog);<br \/>\n}<br \/>\n}<\/p>\n<h3>7&#xff0c;<span style=\"color:#333333\">\u5411\u4e0a\u8f6c\u578b\u548c\u5411\u4e0b\u8f6c\u578b<\/span><\/h3>\n<h4><span style=\"color:#333333\">7.1&#xff0c;\u5411\u4e0a\u8f6c\u578b<\/span><\/h4>\n<p><span style=\"color:#333333\">\u5b9e\u9645\u5c31\u662f\u521b\u5efa\u4e00\u4e2a\u5b50\u7c7b\u5bf9\u8c61&#xff0c;\u5c06\u5176\u5f53\u6210\u7236\u7c7b\u5bf9\u8c61\u6765\u4f7f\u7528<\/span><\/p>\n<p><span style=\"color:#333333\">\u5411\u4e0a\u8f6c\u578b\u7684\u51e0\u79cd\u65b9\u6cd5&#xff1a;<\/span><\/p>\n<p><span style=\"color:#333333\">1. <\/span><span style=\"color:#333333\">\u76f4\u63a5\u8d4b\u503c <\/span><\/p>\n<p>\u200b<br \/>\nclass Animal {<br \/>\n   eat();<br \/>\n} \/\/ \u7236\u7c7b<br \/>\nclass Cat extends Animal {<br \/>\n   eat();<br \/>\n} \/\/ \u5b50\u7c7b<\/p>\n<p>public class Test {<br \/>\n    public static void main(String[] args) {<br \/>\n        \/\/ \u5411\u4e0a\u8f6c\u578b&#xff1a;\u5b50\u7c7b\u5bf9\u8c61 \u2192 \u7236\u7c7b\u5f15\u7528<br \/>\n        Animal animal &#061; new Cat();<br \/>\n        anima.eat();<br \/>\n    }<br \/>\n}<\/p>\n<p>\u200b<\/p>\n<p>\u5173\u952e\u8bf4\u660e&#xff1a;<\/p>\n<ul>\n<li><span style=\"color:#333333\">animal<\/span>\u662f A<span style=\"color:#333333\">nimal<\/span>\u7c7b\u578b\u7684\u5f15\u7528&#xff0c;\u4f46\u6307\u5411\u7684\u662fCat\u00a0\u5bf9\u8c61&#xff08;\u8fd0\u884c\u65f6\u7c7b\u578b\u4e3aCat&#xff09;\u3002<\/li>\n<li>\u6b64\u65f6\u901a\u8fc7\u00a0<span style=\"color:#333333\">animal<\/span>\u00a0\u53ea\u80fd\u8c03\u7528\u7236\u7c7bA<span style=\"color:#333333\">nimal<\/span>\u4e2d\u5b9a\u4e49\u7684\u65b9\u6cd5&#xff08;\u9664\u975e\u5b50\u7c7b\u91cd\u5199\u4e86\u8be5\u65b9\u6cd5&#xff0c;\u89e6\u53d1\u52a8\u6001\u7ed1\u5b9a&#xff09;\u3002<\/li>\n<\/ul>\n<p><span style=\"color:#333333\">2. <\/span><span style=\"color:#333333\">\u65b9\u6cd5\u4f20\u53c2<\/span><\/p>\n<p>class Animal {<br \/>\n    void eat() { System.out.println(&#034;\u52a8\u7269\u5403\u4e1c\u897f&#034;); }<br \/>\n}<br \/>\nclass Dog extends Animal {<br \/>\n    &#064;Override<br \/>\n    void eat() { System.out.println(&#034;\u5c0f\u72d7\u5543\u9aa8\u5934&#034;); }<br \/>\n}<\/p>\n<p>public class Test {<br \/>\n    \/\/ \u4f20\u53c2&#xff1a;\u65b9\u6cd5\u53c2\u6570\u4e3a\u7236\u7c7b\u7c7b\u578b<br \/>\n    public static void feed(Animal animal) {<br \/>\n        animal.eat(); \/\/ \u52a8\u6001\u7ed1\u5b9a&#xff1a;\u8c03\u7528\u5b50\u7c7b\u91cd\u5199\u7684\u65b9\u6cd5<br \/>\n    }<\/p>\n<p>    public static void main(String[] args) {<br \/>\n        Dog dog &#061; new Dog();<br \/>\n        feed(dog); \/\/ \u4f20\u5165\u5b50\u7c7b\u5bf9\u8c61&#xff0c;\u81ea\u52a8\u5411\u4e0a\u8f6c\u578b\u4e3aAnimal\u7c7b\u578b<br \/>\n    }<br \/>\n}<\/p>\n<p><span style=\"color:#333333\">3. <\/span><span style=\"color:#333333\">\u65b9\u6cd5\u8fd4\u56de<\/span><\/p>\n<p>public class TestAnimal {<\/p>\n<p>\/\/ 3. \u4f5c\u8fd4\u56de\u503c&#xff1a;\u8fd4\u56de\u4efb\u610f\u5b50\u7c7b\u5bf9\u8c61<br \/>\npublic static Animal buyAnimal(String var){<br \/>\nif(&#034;\u72d7&#034;.equals(var) ){<br \/>\nreturn new Dog(&#034;\u72d7\u72d7&#034;,1);<br \/>\n}else if(&#034;\u732b&#034; .equals(var)){<br \/>\nreturn new Cat(&#034;\u732b\u732b&#034;, 1);<br \/>\n}else{<br \/>\nreturn null;<br \/>\n}<br \/>\n}<\/p>\n<p>public static void main(String[] args) {<\/p>\n<p>\/\/\u901a\u8fc7\u8fd4\u56de\u503c\u5f15\u7528<br \/>\nAnimal animal &#061; buyAnimal(&#034;\u72d7&#034;);<br \/>\nanimal.eat();<br \/>\nanimal &#061; buyAnimal(&#034;\u732b&#034;);<br \/>\nanimal.eat();<br \/>\n}<br \/>\n}<\/p>\n<p><span style=\"color:#333333\">\u5411\u4e0a\u8f6c\u578b\u7684\u4f18\u70b9&#xff1a;\u8ba9\u4ee3\u7801\u5b9e\u73b0\u66f4\u7b80\u5355\u7075\u6d3b\u3002 <\/span><\/p>\n<p><span style=\"color:#333333\">\u5411\u4e0a\u8f6c\u578b\u7684\u7f3a\u9677&#xff1a;\u4e0d\u80fd\u8c03\u7528\u5230\u5b50\u7c7b\u7279\u6709\u7684\u65b9\u6cd5\u3002<\/span><\/p>\n<h4><span style=\"color:#333333\">7.2&#xff0c;\u5411\u4e0b\u8f6c\u578b<\/span><\/h4>\n<p><span style=\"color:#333333\">1.\u5c06\u4e00\u4e2a\u5b50\u7c7b\u5bf9\u8c61\u7ecf\u8fc7\u5411\u4e0a\u8f6c\u578b\u4e4b\u540e\u5f53\u6210\u7236\u7c7b\u65b9\u6cd5\u4f7f\u7528&#xff0c;\u518d\u65e0\u6cd5\u8c03\u7528\u5b50\u7c7b\u7684\u65b9\u6cd5&#xff0c;\u4f46\u6709\u65f6\u5019\u53ef\u80fd\u9700\u8981\u8c03\u7528\u5b50\u7c7b\u7279\u6709\u7684 \u65b9\u6cd5&#xff0c;\u6b64\u65f6&#xff1a;\u5c06\u7236\u7c7b\u5f15\u7528\u518d\u8fd8\u539f\u4e3a\u5b50\u7c7b\u5bf9\u8c61\u5373\u53ef&#xff0c;\u5373\u5411\u4e0b\u8f6c\u6362\u3002<\/span><\/p>\n<p><span style=\"color:#333333\">2.\u5411\u4e0b\u8f6c\u578b\u7528\u7684\u6bd4\u8f83\u5c11&#xff0c;\u800c\u4e14\u4e0d\u5b89\u5168&#xff0c;\u4e07\u4e00\u8f6c\u6362\u5931\u8d25&#xff0c;\u8fd0\u884c\u65f6\u5c31\u4f1a\u629b\u5f02\u5e38\u3002<\/span><span style=\"color:#333333\">Java<\/span><span style=\"color:#333333\">\u4e2d\u4e3a\u4e86\u63d0\u9ad8\u5411\u4e0b\u8f6c\u578b\u7684\u5b89\u5168\u6027&#xff0c;\u5f15\u5165 \u4e86 instanceof <\/span><span style=\"color:#333333\">&#xff0c;\u5982\u679c\u8be5\u8868\u8fbe\u5f0f\u4e3a<\/span><span style=\"color:#333333\">true<\/span><span style=\"color:#333333\">&#xff0c;\u5219\u53ef\u4ee5\u5b89\u5168\u8f6c\u6362\u3002<\/span><\/p>\n<p>public class TestAnimal {<br \/>\npublic static void main(String[] args) {<br \/>\nCat cat &#061; new Cat(&#034;\u5143\u5b9d&#034;,2);<br \/>\nDog dog &#061; new Dog(&#034;\u5c0f\u4e03&#034;, 1);<br \/>\n\/\/ \u5411\u4e0a\u8f6c\u578b<br \/>\nAnimal animal &#061; cat;<br \/>\nanimal.eat();<br \/>\nanimal &#061; dog;<br \/>\nanimal.eat();<br \/>\nif(animal instanceof Cat){<br \/>\ncat &#061; (Cat)animal;<br \/>\ncat.mew();<br \/>\n}<br \/>\nif(animal instanceof Dog){<br \/>\ndog &#061; (Dog)animal;<br \/>\ndog.bark();<br \/>\n}<br \/>\n}<br \/>\n}<\/p>\n<h3>8&#xff0c;\u591a\u6001\u7684<span style=\"color:#ff9900\">\u4f18\u70b9<\/span><\/h3>\n<p>\u5982\u00a0 \u4e0b\u4ee3\u7801&#xff0c;\u867d\u7136\u901a\u8fc7\u5faa\u73af\u80fd\u591f\u8fbe\u5230\u76ee\u7684&#xff0c;\u4f46\u662f\u5982\u679c\u6253\u5370\u7684\u79cd\u7c7b\u975e\u5e38\u591a&#xff0c;\u8fc7\u7a0b\u5219\u975e\u5e38\u4f4e\u6548<\/p>\n<p>\u200b<br \/>\nclass Shape {<br \/>\n\/\/\u5c5e\u6027&#8230;.<br \/>\npublic void draw() {<br \/>\nSystem.out.println(&#034;\u753b\u56fe\u5f62&#xff01;&#034;);<br \/>\n}<br \/>\n}<\/p>\n<p>\/\/\u5982\u679c\u8fd8\u8981\u6253\u5370\u5176\u4ed6\u7684\u56fe\u5f62&#xff0c;\u5c31\u8981\u91cd\u590d\u6b64\u7ee7\u627f\u6b65\u9aa4&#xff0c;\u5728\u901a\u8fc7main\u65b9\u6cd5\u6765\u6ce8\u610f\u5b9e\u4f8b\u5316\u5b9e\u73b0<br \/>\nclass Rect extends Shape{<br \/>\n&#064;Override<br \/>\npublic void draw() {<br \/>\nSystem.out.println(&#034;\u2666&#034;);<br \/>\n}<br \/>\n}<\/p>\n<p>class Cycle extends Shape{<br \/>\n&#064;Override<br \/>\npublic void draw() {<br \/>\nSystem.out.println(&#034;\u25cf&#034;);<br \/>\n}<br \/>\n}<\/p>\n<p>public static void drawShapes() {<br \/>\nRect rect &#061; new Rect();<br \/>\nCycle cycle &#061; new Cycle();<\/p>\n<p>String[] shapes &#061; {&#034;cycle&#034;, &#034;rect&#034;, &#034;cycle&#034;};<\/p>\n<p>for (String shape : shapes) {<br \/>\nif (shape.equals(&#034;cycle&#034;)) {<br \/>\ncycle.draw();<br \/>\n} else if (shape.equals(&#034;rect&#034;)) {<br \/>\nrect.draw();<br \/>\n}<br \/>\n}<br \/>\n}<\/p>\n<p>\u5982\u679c\u5229\u7528\u591a\u6001&#xff0c;\u4e0d\u7528\u8fc7\u591a\u7684if\u5faa\u73af&#xff0c;\u5219\u975e\u5e38\u9ad8\u6548<\/p>\n<p>\u200b<br \/>\npublic static void drawShapes() {<br \/>\n\/\/ \u521b\u5efa\u4e86\u4e00\u4e2a Shape \u5bf9\u8c61\u7684\u6570\u7ec4.<br \/>\nShape[] shapes &#061; {new Cycle(), new Rect(), new Cycle(),<br \/>\nnew Rect()};<br \/>\nfor (Shape shape : shapes) {<br \/>\nshape.draw();<br \/>\n}<br \/>\n}<\/p>\n<p>\u200b<\/p>\n<h3><span style=\"color:#333333\">9&#xff0c;\u591a\u6001<\/span><span style=\"color:#ff9900\">\u7f3a\u9677<\/span><span style=\"color:#333333\">&#xff1a;\u4ee3\u7801\u7684\u8fd0\u884c\u6548\u7387\u964d\u4f4e<\/span><span style=\"color:#333333\">\u3002 <\/span><\/h3>\n<p><span style=\"color:#777777\">1. <\/span><span style=\"color:#777777\">\u5c5e\u6027\u6ca1\u6709\u591a\u6001\u6027 <\/span><\/p>\n<p><span style=\"color:#777777\">\u5f53\u7236\u7c7b\u548c\u5b50\u7c7b\u90fd\u6709\u540c\u540d\u5c5e\u6027\u7684\u65f6\u5019&#xff0c;\u901a\u8fc7\u7236\u7c7b\u5f15\u7528&#xff0c;\u53ea\u80fd\u5f15\u7528\u7236\u7c7b\u81ea\u5df1\u7684\u6210\u5458\u5c5e\u6027 <\/span><\/p>\n<p><span style=\"color:#777777\">2. <\/span><span style=\"color:#777777\">\u6784\u9020\u65b9\u6cd5\u6ca1\u6709\u591a\u6001\u6027<\/span><\/p>\n<p>class B {<br \/>\npublic B() {<br \/>\n\/\/ do nothing<br \/>\nfunc();<br \/>\n}<br \/>\npublic void func() {<br \/>\nSystem.out.println(&#034;B.func()&#034;);<br \/>\n}<br \/>\n}<br \/>\nclass D extends B {<br \/>\nprivate int num &#061; 1;<br \/>\n&#064;Override<br \/>\npublic void func() {<br \/>\nSystem.out.println(&#034;D.func() &#034; &#043; num);<br \/>\n}<br \/>\n}<br \/>\npublic class Test {<br \/>\npublic static void main(String[] args) {<br \/>\nD d &#061; new D();<br \/>\n}<br \/>\n}<br \/>\n\/\/ \u6267\u884c\u7ed3\u679c<br \/>\nD.func() 0<\/p>\n<p>\u6267\u884c\u987a\u5e8f&#xff1a;<\/p>\n<p><span style=\"color:#333333\">\u6784\u9020<\/span><span style=\"color:#333333\"> D <\/span><span style=\"color:#333333\">\u5bf9\u8c61\u7684\u540c\u65f6<\/span><span style=\"color:#333333\">, <\/span><span style=\"color:#333333\">\u4f1a\u8c03\u7528<\/span><span style=\"color:#333333\"> B <\/span><span style=\"color:#333333\">\u7684\u6784\u9020\u65b9\u6cd5<\/span><span style=\"color:#333333\">. <\/span><\/p>\n<p><span style=\"color:#333333\">B <\/span><span style=\"color:#333333\">\u7684\u6784\u9020\u65b9\u6cd5\u4e2d\u8c03\u7528\u4e86<\/span><span style=\"color:#333333\"> func <\/span><span style=\"color:#333333\">\u65b9\u6cd5<\/span><span style=\"color:#333333\">, <\/span><span style=\"color:#333333\">\u6b64\u65f6\u4f1a\u89e6\u53d1\u52a8\u6001\u7ed1\u5b9a<\/span><span style=\"color:#333333\">, <\/span><span style=\"color:#333333\">\u4f1a\u8c03\u7528\u5230<\/span><span style=\"color:#333333\"> D <\/span><span style=\"color:#333333\">\u4e2d\u7684<\/span><span style=\"color:#333333\"> func <\/span><\/p>\n<p><span style=\"color:#333333\">\u6b64\u65f6<\/span><span style=\"color:#333333\"> D <\/span><span style=\"color:#333333\">\u5bf9\u8c61\u81ea\u8eab\u8fd8\u6ca1\u6709\u6784\u9020<\/span><span style=\"color:#333333\">, <\/span><span style=\"color:#333333\">\u6b64\u65f6<\/span><span style=\"color:#333333\"> num <\/span><span style=\"color:#333333\">\u5904\u5728\u672a\u521d\u59cb\u5316\u7684\u72b6\u6001<\/span><span style=\"color:#333333\">, <\/span><span style=\"color:#333333\">\u503c\u4e3a<\/span><span style=\"color:#333333\"> 0.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>1&#xff0c;\u4ec0\u4e48\u662f\u591a\u6001&#xff1f;\u662f\u591a\u79cd\u5f62\u6001&#xff0c;\u5177\u4f53\u70b9\u5c31\u662f\u53bb\u5b8c\u6210\u67d0\u4e2a\u884c\u4e3a&#xff0c;\u5f53\u4e0d\u540c\u7684\u5bf9\u8c61\u53bb\u5b8c\u6210\u65f6\u4f1a\u4ea7\u751f\u51fa\u4e0d\u540c \u7684\u72b6 \u6001&#xff0c;\u6bd4\u5982&#xff1a;\u90fd\u662f\u5403\u996d&#xff0c;\u9e1f\u5403\u9e1f\u7cae&#xff0c;\u72d7\u5403\u72d7\u7cae&#xff0c;\u4eba\u5403\u996d&#8230;,2&#xff0c;\u4e3a\u4ec0\u4e48\u6709\u591a\u6001&#xff1f;\u4ece\u4e00\u4e2a\u521d\u59cb\u8005\u7684\u89d2\u5ea6\u53bb\u770b&#xff0c;\u5c31\u662f\u4e3a\u4e86\u65b9\u4fbf&#xff0c;\u4e0b\u9762\u4f1a\u7528\u4ee3\u7801\u6765\u8bf4\u660e\u30023&#xff0c;\u591a\u6001\u5b9e\u73b0\u6761\u4ef61. \u5fc5\u987b\u5728\u7ee7\u627f\u4f53\u7cfb\u4e0b 2. \u5b50\u7c7b\u5fc5\u987b\u8981\u5bf9\u7236<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[99,190],"topic":[],"class_list":["post-76190","post","type-post","status-publish","format-standard","hentry","category-server","tag-java","tag-190"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u6ce8\u610f\uff1a\u591a\u6001\u4e0d\u662f\u201c\u591a\u53d8\u6001\u201d - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\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.wsisp.com\/helps\/76190.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u6ce8\u610f\uff1a\u591a\u6001\u4e0d\u662f\u201c\u591a\u53d8\u6001\u201d - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"1&#xff0c;\u4ec0\u4e48\u662f\u591a\u6001&#xff1f;\u662f\u591a\u79cd\u5f62\u6001&#xff0c;\u5177\u4f53\u70b9\u5c31\u662f\u53bb\u5b8c\u6210\u67d0\u4e2a\u884c\u4e3a&#xff0c;\u5f53\u4e0d\u540c\u7684\u5bf9\u8c61\u53bb\u5b8c\u6210\u65f6\u4f1a\u4ea7\u751f\u51fa\u4e0d\u540c \u7684\u72b6 \u6001&#xff0c;\u6bd4\u5982&#xff1a;\u90fd\u662f\u5403\u996d&#xff0c;\u9e1f\u5403\u9e1f\u7cae&#xff0c;\u72d7\u5403\u72d7\u7cae&#xff0c;\u4eba\u5403\u996d...,2&#xff0c;\u4e3a\u4ec0\u4e48\u6709\u591a\u6001&#xff1f;\u4ece\u4e00\u4e2a\u521d\u59cb\u8005\u7684\u89d2\u5ea6\u53bb\u770b&#xff0c;\u5c31\u662f\u4e3a\u4e86\u65b9\u4fbf&#xff0c;\u4e0b\u9762\u4f1a\u7528\u4ee3\u7801\u6765\u8bf4\u660e\u30023&#xff0c;\u591a\u6001\u5b9e\u73b0\u6761\u4ef61. \u5fc5\u987b\u5728\u7ee7\u627f\u4f53\u7cfb\u4e0b 2. \u5b50\u7c7b\u5fc5\u987b\u8981\u5bf9\u7236\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/76190.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-02-21T14:49:08+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/76190.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/76190.html\",\"name\":\"\u6ce8\u610f\uff1a\u591a\u6001\u4e0d\u662f\u201c\u591a\u53d8\u6001\u201d - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-02-21T14:49:08+00:00\",\"dateModified\":\"2026-02-21T14:49:08+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/76190.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/76190.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/76190.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u6ce8\u610f\uff1a\u591a\u6001\u4e0d\u662f\u201c\u591a\u53d8\u6001\u201d\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u6ce8\u610f\uff1a\u591a\u6001\u4e0d\u662f\u201c\u591a\u53d8\u6001\u201d - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","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.wsisp.com\/helps\/76190.html","og_locale":"zh_CN","og_type":"article","og_title":"\u6ce8\u610f\uff1a\u591a\u6001\u4e0d\u662f\u201c\u591a\u53d8\u6001\u201d - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"1&#xff0c;\u4ec0\u4e48\u662f\u591a\u6001&#xff1f;\u662f\u591a\u79cd\u5f62\u6001&#xff0c;\u5177\u4f53\u70b9\u5c31\u662f\u53bb\u5b8c\u6210\u67d0\u4e2a\u884c\u4e3a&#xff0c;\u5f53\u4e0d\u540c\u7684\u5bf9\u8c61\u53bb\u5b8c\u6210\u65f6\u4f1a\u4ea7\u751f\u51fa\u4e0d\u540c \u7684\u72b6 \u6001&#xff0c;\u6bd4\u5982&#xff1a;\u90fd\u662f\u5403\u996d&#xff0c;\u9e1f\u5403\u9e1f\u7cae&#xff0c;\u72d7\u5403\u72d7\u7cae&#xff0c;\u4eba\u5403\u996d...,2&#xff0c;\u4e3a\u4ec0\u4e48\u6709\u591a\u6001&#xff1f;\u4ece\u4e00\u4e2a\u521d\u59cb\u8005\u7684\u89d2\u5ea6\u53bb\u770b&#xff0c;\u5c31\u662f\u4e3a\u4e86\u65b9\u4fbf&#xff0c;\u4e0b\u9762\u4f1a\u7528\u4ee3\u7801\u6765\u8bf4\u660e\u30023&#xff0c;\u591a\u6001\u5b9e\u73b0\u6761\u4ef61. \u5fc5\u987b\u5728\u7ee7\u627f\u4f53\u7cfb\u4e0b 2. \u5b50\u7c7b\u5fc5\u987b\u8981\u5bf9\u7236","og_url":"https:\/\/www.wsisp.com\/helps\/76190.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-02-21T14:49:08+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"4 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/76190.html","url":"https:\/\/www.wsisp.com\/helps\/76190.html","name":"\u6ce8\u610f\uff1a\u591a\u6001\u4e0d\u662f\u201c\u591a\u53d8\u6001\u201d - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-02-21T14:49:08+00:00","dateModified":"2026-02-21T14:49:08+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/76190.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/76190.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/76190.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u6ce8\u610f\uff1a\u591a\u6001\u4e0d\u662f\u201c\u591a\u53d8\u6001\u201d"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/76190","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=76190"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/76190\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=76190"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=76190"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=76190"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=76190"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}