{"id":69852,"date":"2026-02-01T05:42:14","date_gmt":"2026-01-31T21:42:14","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/69852.html"},"modified":"2026-02-01T05:42:14","modified_gmt":"2026-01-31T21:42:14","slug":"%e8%93%9d%e6%a1%a5%e6%9d%afjava-%e5%90%af%e8%92%99%e4%b9%8b%e8%b7%af%ef%bc%88%e4%b8%83%ef%bc%89%e7%bb%a7%e6%89%bf%e5%a4%9a%e6%80%81","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/69852.html","title":{"rendered":"\u84dd\u6865\u676fJAVA--\u542f\u8499\u4e4b\u8def\uff08\u4e03\uff09\u7ee7\u627f\u591a\u6001"},"content":{"rendered":"<h2>\u4e00\u524d\u8a00<\/h2>\n<p>\u4eca\u5929\u4e0d\u77e5\u9053\u54ea\u6765\u7684\u6597\u5fd7&#xff0c;\u611f\u89c9\u72b6\u6001\u5728\u56de\u5f52&#xff0c;\u6240\u6709\u591a\u5199\u4e00\u70b9&#xff0c;\u8fd9\u6b21\u7684\u5185\u5bb9\u6211\u611f\u89c9\u662f\u5f88\u91cd\u8981\u7684\u3002<\/p>\n<p>\u5927\u5bb6\u4e00\u8d77\u52aa\u529b\u5427\u3002<\/p>\n<h2>\u4e8c\u4e3b\u8981\u5185\u5bb9<\/h2>\n<h3>\u7ee7\u627f<\/h3>\n<p>\u5728\u524d\u9762\u7684\u7ae0\u8282\u4e2d&#xff0c;\u6211\u4eec\u5df2\u7ecf\u5b9a\u4e49\u4e86Person\u7c7b&#xff1a;<\/p>\n<p>class Person {<br \/>\n    private String name;<br \/>\n    private int age;<\/p>\n<p>    public String getName() {&#8230;}<br \/>\n    public void setName(String name) {&#8230;}<br \/>\n    public int getAge() {&#8230;}<br \/>\n    public void setAge(int age) {&#8230;}<br \/>\n}<\/p>\n<p>\u73b0\u5728&#xff0c;\u5047\u8bbe\u9700\u8981\u5b9a\u4e49\u4e00\u4e2aStudent\u7c7b&#xff0c;\u5b57\u6bb5\u5982\u4e0b&#xff1a;<\/p>\n<p>class Student {<br \/>\n    private String name;<br \/>\n    private int age;<br \/>\n    private int score;<\/p>\n<p>    public String getName() {&#8230;}<br \/>\n    public void setName(String name) {&#8230;}<br \/>\n    public int getAge() {&#8230;}<br \/>\n    public void setAge(int age) {&#8230;}<br \/>\n    public int getScore() { \u2026 }<br \/>\n    public void setScore(int score) { \u2026 }<br \/>\n}<\/p>\n<p>\u4ed4\u7ec6\u89c2\u5bdf&#xff0c;\u53d1\u73b0Student\u7c7b\u5305\u542b\u4e86Person\u7c7b\u5df2\u6709\u7684\u5b57\u6bb5\u548c\u65b9\u6cd5&#xff0c;\u53ea\u662f\u591a\u51fa\u4e86\u4e00\u4e2ascore\u5b57\u6bb5\u548c\u76f8\u5e94\u7684getScore()\u3001setScore()\u65b9\u6cd5\u3002<\/p>\n<p>\u80fd\u4e0d\u80fd\u5728Student\u4e2d\u4e0d\u8981\u5199\u91cd\u590d\u7684\u4ee3\u7801&#xff1f;<\/p>\n<p>\u8fd9\u4e2a\u65f6\u5019&#xff0c;\u7ee7\u627f\u5c31\u6d3e\u4e0a\u7528\u573a\u4e86\u3002<\/p>\n<p>\u7ee7\u627f\u662f\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\u4e2d\u975e\u5e38\u5f3a\u5927\u7684\u4e00\u79cd\u673a\u5236&#xff0c;\u5b83\u9996\u5148\u53ef\u4ee5\u590d\u7528\u4ee3\u7801\u3002\u5f53\u6211\u4eec\u8ba9Student\u4ecePerson\u7ee7\u627f\u65f6&#xff0c;Student\u5c31\u83b7\u5f97\u4e86Person\u7684\u6240\u6709\u529f\u80fd&#xff0c;\u6211\u4eec\u53ea\u9700\u8981\u4e3aStudent\u7f16\u5199\u65b0\u589e\u7684\u529f\u80fd\u3002<\/p>\n<p>Java\u4f7f\u7528extends\u5173\u952e\u5b57\u6765\u5b9e\u73b0\u7ee7\u627f&#xff1a;<\/p>\n<p>class Person {<br \/>\n    private String name;<br \/>\n    private int age;<\/p>\n<p>    public String getName() {&#8230;}<br \/>\n    public void setName(String name) {&#8230;}<br \/>\n    public int getAge() {&#8230;}<br \/>\n    public void setAge(int age) {&#8230;}<br \/>\n}<\/p>\n<p>class Student extends Person {<br \/>\n    \/\/ \u4e0d\u8981\u91cd\u590dname\u548cage\u5b57\u6bb5\/\u65b9\u6cd5,<br \/>\n    \/\/ \u53ea\u9700\u8981\u5b9a\u4e49\u65b0\u589escore\u5b57\u6bb5\/\u65b9\u6cd5:<br \/>\n    private int score;<\/p>\n<p>    public int getScore() { \u2026 }<br \/>\n    public void setScore(int score) { \u2026 }<br \/>\n}<\/p>\n<p>\u53ef\u89c1&#xff0c;\u901a\u8fc7\u7ee7\u627f&#xff0c;Student\u53ea\u9700\u8981\u7f16\u5199\u989d\u5916\u7684\u529f\u80fd&#xff0c;\u4e0d\u518d\u9700\u8981\u91cd\u590d\u4ee3\u7801\u3002<\/p>\n<p>\u00a0\u6ce8\u610f<\/p>\n<p>\u5b50\u7c7b\u81ea\u52a8\u83b7\u5f97\u4e86\u7236\u7c7b\u7684\u6240\u6709\u5b57\u6bb5&#xff0c;\u4e25\u7981\u5b9a\u4e49\u4e0e\u7236\u7c7b\u91cd\u540d\u7684\u5b57\u6bb5&#xff01;<\/p>\n<p>\u5728OOP\u7684\u672f\u8bed\u4e2d&#xff0c;\u6211\u4eec\u628aPerson\u79f0\u4e3a\u8d85\u7c7b&#xff08;super class&#xff09;&#xff0c;\u7236\u7c7b&#xff08;parent class&#xff09;&#xff0c;\u57fa\u7c7b&#xff08;base class&#xff09;&#xff0c;\u628aStudent\u79f0\u4e3a\u5b50\u7c7b&#xff08;subclass&#xff09;&#xff0c;\u6269\u5c55\u7c7b&#xff08;extended class&#xff09;\u3002<\/p>\n<h4>\u7ee7\u627f\u6811<\/h4>\n<p>\u6ce8\u610f\u5230\u6211\u4eec\u5728\u5b9a\u4e49Person\u7684\u65f6\u5019&#xff0c;\u6ca1\u6709\u5199extends\u3002\u5728Java\u4e2d&#xff0c;\u6ca1\u6709\u660e\u786e\u5199extends\u7684\u7c7b&#xff0c;\u7f16\u8bd1\u5668\u4f1a\u81ea\u52a8\u52a0\u4e0aextends Object\u3002\u6240\u4ee5&#xff0c;\u4efb\u4f55\u7c7b&#xff0c;\u9664\u4e86Object&#xff0c;\u90fd\u4f1a\u7ee7\u627f\u81ea\u67d0\u4e2a\u7c7b\u3002\u4e0b\u56fe\u662fPerson\u3001Student\u7684\u7ee7\u627f\u6811&#xff1a;<\/p>\n<p>\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510<br \/>\n\u2502  Object   \u2502<br \/>\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518<br \/>\n      \u25b2<br \/>\n      \u2502<br \/>\n\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510<br \/>\n\u2502  Person   \u2502<br \/>\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518<br \/>\n      \u25b2<br \/>\n      \u2502<br \/>\n\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510<br \/>\n\u2502  Student  \u2502<br \/>\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518<\/p>\n<p>Java\u53ea\u5141\u8bb8\u4e00\u4e2aclass\u7ee7\u627f\u81ea\u4e00\u4e2a\u7c7b&#xff0c;\u56e0\u6b64&#xff0c;\u4e00\u4e2a\u7c7b\u6709\u4e14\u4ec5\u6709\u4e00\u4e2a\u7236\u7c7b\u3002\u53ea\u6709Object\u7279\u6b8a&#xff0c;\u5b83\u6ca1\u6709\u7236\u7c7b\u3002<\/p>\n<p>\u7c7b\u4f3c\u7684&#xff0c;\u5982\u679c\u6211\u4eec\u5b9a\u4e49\u4e00\u4e2a\u7ee7\u627f\u81eaPerson\u7684Teacher&#xff0c;\u5b83\u4eec\u7684\u7ee7\u627f\u6811\u5173\u7cfb\u5982\u4e0b&#xff1a;<\/p>\n<p>       \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510<br \/>\n       \u2502  Object   \u2502<br \/>\n       \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518<br \/>\n             \u25b2<br \/>\n             \u2502<br \/>\n       \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510<br \/>\n       \u2502  Person   \u2502<br \/>\n       \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518<br \/>\n          \u25b2     \u25b2<br \/>\n          \u2502     \u2502<br \/>\n          \u2502     \u2502<br \/>\n\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510 \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510<br \/>\n\u2502  Student  \u2502 \u2502  Teacher  \u2502<br \/>\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518 \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518<\/p>\n<h4>protected<\/h4>\n<p>\u7ee7\u627f\u6709\u4e2a\u7279\u70b9&#xff0c;\u5c31\u662f\u5b50\u7c7b\u65e0\u6cd5\u8bbf\u95ee\u7236\u7c7b\u7684private\u5b57\u6bb5\u6216\u8005private\u65b9\u6cd5\u3002\u4f8b\u5982&#xff0c;Student\u7c7b\u5c31\u65e0\u6cd5\u8bbf\u95eePerson\u7c7b\u7684name\u548cage\u5b57\u6bb5&#xff1a;<\/p>\n<p>class Person {<br \/>\n    private String name;<br \/>\n    private int age;<br \/>\n}<\/p>\n<p>class Student extends Person {<br \/>\n    public String hello() {<br \/>\n        return &#034;Hello, &#034; &#043; name; \/\/ \u7f16\u8bd1\u9519\u8bef&#xff1a;\u65e0\u6cd5\u8bbf\u95eename\u5b57\u6bb5<br \/>\n    }<br \/>\n}<\/p>\n<p>\u8fd9\u4f7f\u5f97\u7ee7\u627f\u7684\u4f5c\u7528\u88ab\u524a\u5f31\u4e86\u3002\u4e3a\u4e86\u8ba9\u5b50\u7c7b\u53ef\u4ee5\u8bbf\u95ee\u7236\u7c7b\u7684\u5b57\u6bb5&#xff0c;\u6211\u4eec\u9700\u8981\u628aprivate\u6539\u4e3aprotected\u3002\u7528protected\u4fee\u9970\u7684\u5b57\u6bb5\u53ef\u4ee5\u88ab\u5b50\u7c7b\u8bbf\u95ee&#xff1a;<\/p>\n<p>class Person {<br \/>\n    protected String name;<br \/>\n    protected int age;<br \/>\n}<\/p>\n<p>class Student extends Person {<br \/>\n    public String hello() {<br \/>\n        return &#034;Hello, &#034; &#043; name; \/\/ OK!<br \/>\n    }<br \/>\n}<\/p>\n<p>\u56e0\u6b64&#xff0c;protected\u5173\u952e\u5b57\u53ef\u4ee5\u628a\u5b57\u6bb5\u548c\u65b9\u6cd5\u7684\u8bbf\u95ee\u6743\u9650\u63a7\u5236\u5728\u7ee7\u627f\u6811\u5185\u90e8&#xff0c;\u4e00\u4e2aprotected\u5b57\u6bb5\u548c\u65b9\u6cd5\u53ef\u4ee5\u88ab\u5176\u5b50\u7c7b&#xff0c;\u4ee5\u53ca\u5b50\u7c7b\u7684\u5b50\u7c7b\u6240\u8bbf\u95ee&#xff0c;\u540e\u9762\u6211\u4eec\u8fd8\u4f1a\u8be6\u7ec6\u8bb2\u89e3\u3002<\/p>\n<h4>super<\/h4>\n<p>super\u5173\u952e\u5b57\u8868\u793a\u7236\u7c7b&#xff08;\u8d85\u7c7b&#xff09;\u3002\u5b50\u7c7b\u5f15\u7528\u7236\u7c7b\u7684\u5b57\u6bb5\u65f6&#xff0c;\u53ef\u4ee5\u7528super.fieldName\u3002\u4f8b\u5982&#xff1a;<\/p>\n<p>class Student extends Person {<br \/>\n    public String hello() {<br \/>\n        return &#034;Hello, &#034; &#043; super.name;<br \/>\n    }<br \/>\n}<\/p>\n<p>\u5b9e\u9645\u4e0a&#xff0c;\u8fd9\u91cc\u4f7f\u7528super.name&#xff0c;\u6216\u8005this.name&#xff0c;\u6216\u8005name&#xff0c;\u6548\u679c\u90fd\u662f\u4e00\u6837\u7684\u3002\u7f16\u8bd1\u5668\u4f1a\u81ea\u52a8\u5b9a\u4f4d\u5230\u7236\u7c7b\u7684name\u5b57\u6bb5\u3002<\/p>\n<p>\u4f46\u662f&#xff0c;\u5728\u67d0\u4e9b\u65f6\u5019&#xff0c;\u5c31\u5fc5\u987b\u4f7f\u7528super\u3002\u6211\u4eec\u6765\u770b\u4e00\u4e2a\u4f8b\u5b50&#xff1a;<\/p>\n<p>\/\/ super<br \/>\npublic class Main {<br \/>\n    public static void main(String[] args) {<br \/>\n        Student s &#061; new Student(&#034;Xiao Ming&#034;, 12, 89);<br \/>\n    }<br \/>\n}<\/p>\n<p>class Person {<br \/>\n    protected String name;<br \/>\n    protected int age;<\/p>\n<p>    public Person(String name, int age) {<br \/>\n        this.name &#061; name;<br \/>\n        this.age &#061; age;<br \/>\n    }<br \/>\n}<\/p>\n<p>class Student extends Person {<br \/>\n    protected int score;<\/p>\n<p>    public Student(String name, int age, int score) {<br \/>\n        this.score &#061; score;<br \/>\n    }<br \/>\n}<\/p>\n<p>\u8fd0\u884c\u4e0a\u9762\u7684\u4ee3\u7801&#xff0c;\u4f1a\u5f97\u5230\u4e00\u4e2a\u7f16\u8bd1\u9519\u8bef&#xff0c;\u5927\u610f\u662f\u5728Student\u7684\u6784\u9020\u65b9\u6cd5\u4e2d&#xff0c;\u65e0\u6cd5\u8c03\u7528Person\u7684\u6784\u9020\u65b9\u6cd5\u3002<\/p>\n<p>\u8fd9\u662f\u56e0\u4e3a\u5728Java\u4e2d&#xff0c;\u4efb\u4f55class\u7684\u6784\u9020\u65b9\u6cd5&#xff0c;\u7b2c\u4e00\u884c\u8bed\u53e5\u5fc5\u987b\u662f\u8c03\u7528\u7236\u7c7b\u7684\u6784\u9020\u65b9\u6cd5\u3002\u5982\u679c\u6ca1\u6709\u660e\u786e\u5730\u8c03\u7528\u7236\u7c7b\u7684\u6784\u9020\u65b9\u6cd5&#xff0c;\u7f16\u8bd1\u5668\u4f1a\u5e2e\u6211\u4eec\u81ea\u52a8\u52a0\u4e00\u53e5super();&#xff0c;\u6240\u4ee5&#xff0c;Student\u7c7b\u7684\u6784\u9020\u65b9\u6cd5\u5b9e\u9645\u4e0a\u662f\u8fd9\u6837&#xff1a;<\/p>\n<p>class Student extends Person {<br \/>\n    protected int score;<\/p>\n<p>    public Student(String name, int age, int score) {<br \/>\n        super(); \/\/ \u81ea\u52a8\u8c03\u7528\u7236\u7c7b\u7684\u6784\u9020\u65b9\u6cd5<br \/>\n        this.score &#061; score;<br \/>\n    }<br \/>\n}<\/p>\n<p>\u4f46\u662f&#xff0c;Person\u7c7b\u5e76\u6ca1\u6709\u65e0\u53c2\u6570\u7684\u6784\u9020\u65b9\u6cd5&#xff0c;\u56e0\u6b64&#xff0c;\u7f16\u8bd1\u5931\u8d25\u3002<\/p>\n<p>\u89e3\u51b3\u65b9\u6cd5\u662f\u8c03\u7528Person\u7c7b\u5b58\u5728\u7684\u67d0\u4e2a\u6784\u9020\u65b9\u6cd5\u3002\u4f8b\u5982&#xff1a;<\/p>\n<p>class Student extends Person {<br \/>\n    protected int score;<\/p>\n<p>    public Student(String name, int age, int score) {<br \/>\n        super(name, age); \/\/ \u8c03\u7528\u7236\u7c7b\u7684\u6784\u9020\u65b9\u6cd5Person(String, int)<br \/>\n        this.score &#061; score;<br \/>\n    }<br \/>\n}<\/p>\n<p>\u8fd9\u6837\u5c31\u53ef\u4ee5\u6b63\u5e38\u7f16\u8bd1\u4e86&#xff01;<\/p>\n<p>\u56e0\u6b64\u6211\u4eec\u5f97\u51fa\u7ed3\u8bba&#xff1a;\u5982\u679c\u7236\u7c7b\u6ca1\u6709\u9ed8\u8ba4\u7684\u6784\u9020\u65b9\u6cd5&#xff0c;\u5b50\u7c7b\u5c31\u5fc5\u987b\u663e\u5f0f\u8c03\u7528super()\u5e76\u7ed9\u51fa\u53c2\u6570\u4ee5\u4fbf\u8ba9\u7f16\u8bd1\u5668\u5b9a\u4f4d\u5230\u7236\u7c7b\u7684\u4e00\u4e2a\u5408\u9002\u7684\u6784\u9020\u65b9\u6cd5\u3002<\/p>\n<p>\u8fd9\u91cc\u8fd8\u987a\u5e26\u5f15\u51fa\u4e86\u53e6\u4e00\u4e2a\u95ee\u9898&#xff1a;\u5373\u5b50\u7c7b\u4e0d\u4f1a\u7ee7\u627f\u4efb\u4f55\u7236\u7c7b\u7684\u6784\u9020\u65b9\u6cd5\u3002\u5b50\u7c7b\u9ed8\u8ba4\u7684\u6784\u9020\u65b9\u6cd5\u662f\u7f16\u8bd1\u5668\u81ea\u52a8\u751f\u6210\u7684&#xff0c;\u4e0d\u662f\u7ee7\u627f\u7684\u3002<\/p>\n<h4>\u963b\u6b62\u7ee7\u627f<\/h4>\n<p>\u6b63\u5e38\u60c5\u51b5\u4e0b&#xff0c;\u53ea\u8981\u67d0\u4e2aclass\u6ca1\u6709final\u4fee\u9970\u7b26&#xff0c;\u90a3\u4e48\u4efb\u4f55\u7c7b\u90fd\u53ef\u4ee5\u4ece\u8be5class\u7ee7\u627f\u3002<\/p>\n<p>\u4eceJava 15\u5f00\u59cb&#xff0c;\u5141\u8bb8\u4f7f\u7528sealed\u4fee\u9970class&#xff0c;\u5e76\u901a\u8fc7permits\u660e\u786e\u5199\u51fa\u80fd\u591f\u4ece\u8be5class\u7ee7\u627f\u7684\u5b50\u7c7b\u540d\u79f0\u3002<\/p>\n<p>\u4f8b\u5982&#xff0c;\u5b9a\u4e49\u4e00\u4e2aShape\u7c7b&#xff1a;<\/p>\n<p>public sealed class Shape permits Rect, Circle, Triangle {<br \/>\n    &#8230;<br \/>\n}<\/p>\n<p>\u4e0a\u8ff0Shape\u7c7b\u5c31\u662f\u4e00\u4e2asealed\u7c7b&#xff0c;\u5b83\u53ea\u5141\u8bb8\u6307\u5b9a\u76843\u4e2a\u7c7b\u7ee7\u627f\u5b83\u3002\u5982\u679c\u5199&#xff1a;<\/p>\n<p>public final class Rect extends Shape {&#8230;}<\/p>\n<p>\u662f\u6ca1\u95ee\u9898\u7684&#xff0c;\u56e0\u4e3aRect\u51fa\u73b0\u5728Shape\u7684permits\u5217\u8868\u4e2d\u3002\u4f46\u662f&#xff0c;\u5982\u679c\u5b9a\u4e49\u4e00\u4e2aEllipse\u5c31\u4f1a\u62a5\u9519&#xff1a;<\/p>\n<p>public final class Ellipse extends Shape {&#8230;}<br \/>\n\/\/ Compile error: class is not allowed to extend sealed class: Shape<\/p>\n<p>\u539f\u56e0\u662fEllipse\u5e76\u672a\u51fa\u73b0\u5728Shape\u7684permits\u5217\u8868\u4e2d\u3002\u8fd9\u79cdsealed\u7c7b\u4e3b\u8981\u7528\u4e8e\u4e00\u4e9b\u6846\u67b6&#xff0c;\u9632\u6b62\u7ee7\u627f\u88ab\u6ee5\u7528\u3002<\/p>\n<p>sealed\u7c7b\u5728Java 15\u4e2d\u76ee\u524d\u662f\u9884\u89c8\u72b6\u6001&#xff0c;\u8981\u542f\u7528\u5b83&#xff0c;\u5fc5\u987b\u4f7f\u7528\u53c2\u6570&#8211;enable-preview\u548c&#8211;source 15\u3002<\/p>\n<h4>\u5411\u4e0a\u8f6c\u578b<\/h4>\n<p>\u5982\u679c\u4e00\u4e2a\u5f15\u7528\u53d8\u91cf\u7684\u7c7b\u578b\u662fStudent&#xff0c;\u90a3\u4e48\u5b83\u53ef\u4ee5\u6307\u5411\u4e00\u4e2aStudent\u7c7b\u578b\u7684\u5b9e\u4f8b&#xff1a;<\/p>\n<p>Student s &#061; new Student();<\/p>\n<p>\u5982\u679c\u4e00\u4e2a\u5f15\u7528\u7c7b\u578b\u7684\u53d8\u91cf\u662fPerson&#xff0c;\u90a3\u4e48\u5b83\u53ef\u4ee5\u6307\u5411\u4e00\u4e2aPerson\u7c7b\u578b\u7684\u5b9e\u4f8b&#xff1a;<\/p>\n<p>Person p &#061; new Person();<\/p>\n<p>\u73b0\u5728\u95ee\u9898\u6765\u4e86&#xff1a;\u5982\u679cStudent\u662f\u4ecePerson\u7ee7\u627f\u4e0b\u6765\u7684&#xff0c;\u90a3\u4e48&#xff0c;\u4e00\u4e2a\u5f15\u7528\u7c7b\u578b\u4e3aPerson\u7684\u53d8\u91cf&#xff0c;\u80fd\u5426\u6307\u5411Student\u7c7b\u578b\u7684\u5b9e\u4f8b&#xff1f;<\/p>\n<p>Person p &#061; new Student(); \/\/ ???<\/p>\n<p>\u6d4b\u8bd5\u4e00\u4e0b\u5c31\u53ef\u4ee5\u53d1\u73b0&#xff0c;\u8fd9\u79cd\u6307\u5411\u662f\u5141\u8bb8\u7684&#xff01;<\/p>\n<p>\u8fd9\u662f\u56e0\u4e3aStudent\u7ee7\u627f\u81eaPerson&#xff0c;\u56e0\u6b64&#xff0c;\u5b83\u62e5\u6709Person\u7684\u5168\u90e8\u529f\u80fd\u3002Person\u7c7b\u578b\u7684\u53d8\u91cf&#xff0c;\u5982\u679c\u6307\u5411Student\u7c7b\u578b\u7684\u5b9e\u4f8b&#xff0c;\u5bf9\u5b83\u8fdb\u884c\u64cd\u4f5c&#xff0c;\u662f\u6ca1\u6709\u95ee\u9898\u7684&#xff01;<\/p>\n<p>\u8fd9\u79cd\u628a\u4e00\u4e2a\u5b50\u7c7b\u7c7b\u578b\u5b89\u5168\u5730\u53d8\u4e3a\u7236\u7c7b\u7c7b\u578b\u7684\u8d4b\u503c&#xff0c;\u88ab\u79f0\u4e3a\u5411\u4e0a\u8f6c\u578b&#xff08;upcasting&#xff09;\u3002<\/p>\n<p>\u5411\u4e0a\u8f6c\u578b\u5b9e\u9645\u4e0a\u662f\u628a\u4e00\u4e2a\u5b50\u7c7b\u578b\u5b89\u5168\u5730\u53d8\u4e3a\u66f4\u52a0\u62bd\u8c61\u7684\u7236\u7c7b\u578b&#xff1a;<\/p>\n<p>Student s &#061; new Student();<br \/>\nPerson p &#061; s; \/\/ upcasting, ok<br \/>\nObject o1 &#061; p; \/\/ upcasting, ok<br \/>\nObject o2 &#061; s; \/\/ upcasting, ok<\/p>\n<p>\u6ce8\u610f\u5230\u7ee7\u627f\u6811\u662fStudent &gt; Person &gt; Object&#xff0c;\u6240\u4ee5&#xff0c;\u53ef\u4ee5\u628aStudent\u7c7b\u578b\u8f6c\u578b\u4e3aPerson&#xff0c;\u6216\u8005\u66f4\u9ad8\u5c42\u6b21\u7684Object\u3002<\/p>\n<h4>\u5411\u4e0b\u8f6c\u578b<\/h4>\n<p>\u548c\u5411\u4e0a\u8f6c\u578b\u76f8\u53cd&#xff0c;\u5982\u679c\u628a\u4e00\u4e2a\u7236\u7c7b\u7c7b\u578b\u5f3a\u5236\u8f6c\u578b\u4e3a\u5b50\u7c7b\u7c7b\u578b&#xff0c;\u5c31\u662f\u5411\u4e0b\u8f6c\u578b&#xff08;downcasting&#xff09;\u3002\u4f8b\u5982&#xff1a;<\/p>\n<p>Person p1 &#061; new Student(); \/\/ upcasting, ok<br \/>\nPerson p2 &#061; new Person();<br \/>\nStudent s1 &#061; (Student) p1; \/\/ ok<br \/>\nStudent s2 &#061; (Student) p2; \/\/ runtime error! ClassCastException!<\/p>\n<p>\u5982\u679c\u6d4b\u8bd5\u4e0a\u9762\u7684\u4ee3\u7801&#xff0c;\u53ef\u4ee5\u53d1\u73b0&#xff1a;<\/p>\n<p>Person\u7c7b\u578bp1\u5b9e\u9645\u6307\u5411Student\u5b9e\u4f8b&#xff0c;Person\u7c7b\u578b\u53d8\u91cfp2\u5b9e\u9645\u6307\u5411Person\u5b9e\u4f8b\u3002\u5728\u5411\u4e0b\u8f6c\u578b\u7684\u65f6\u5019&#xff0c;\u628ap1\u8f6c\u578b\u4e3aStudent\u4f1a\u6210\u529f&#xff0c;\u56e0\u4e3ap1\u786e\u5b9e\u6307\u5411Student\u5b9e\u4f8b&#xff0c;\u628ap2\u8f6c\u578b\u4e3aStudent\u4f1a\u5931\u8d25&#xff0c;\u56e0\u4e3ap2\u7684\u5b9e\u9645\u7c7b\u578b\u662fPerson&#xff0c;\u4e0d\u80fd\u628a\u7236\u7c7b\u53d8\u4e3a\u5b50\u7c7b&#xff0c;\u56e0\u4e3a\u5b50\u7c7b\u529f\u80fd\u6bd4\u7236\u7c7b\u591a&#xff0c;\u591a\u7684\u529f\u80fd\u65e0\u6cd5\u51ed\u7a7a\u53d8\u51fa\u6765\u3002<\/p>\n<p>\u56e0\u6b64&#xff0c;\u5411\u4e0b\u8f6c\u578b\u5f88\u53ef\u80fd\u4f1a\u5931\u8d25\u3002\u5931\u8d25\u7684\u65f6\u5019&#xff0c;Java\u865a\u62df\u673a\u4f1a\u62a5ClassCastException\u3002<\/p>\n<p>\u4e3a\u4e86\u907f\u514d\u5411\u4e0b\u8f6c\u578b\u51fa\u9519&#xff0c;Java\u63d0\u4f9b\u4e86instanceof\u64cd\u4f5c\u7b26&#xff0c;\u53ef\u4ee5\u5148\u5224\u65ad\u4e00\u4e2a\u5b9e\u4f8b\u7a76\u7adf\u662f\u4e0d\u662f\u67d0\u79cd\u7c7b\u578b&#xff1a;<\/p>\n<p>Person p &#061; new Person();<br \/>\nSystem.out.println(p instanceof Person); \/\/ true<br \/>\nSystem.out.println(p instanceof Student); \/\/ false<\/p>\n<p>Student s &#061; new Student();<br \/>\nSystem.out.println(s instanceof Person); \/\/ true<br \/>\nSystem.out.println(s instanceof Student); \/\/ true<\/p>\n<p>Student n &#061; null;<br \/>\nSystem.out.println(n instanceof Student); \/\/ false<\/p>\n<p>instanceof\u5b9e\u9645\u4e0a\u5224\u65ad\u4e00\u4e2a\u53d8\u91cf\u6240\u6307\u5411\u7684\u5b9e\u4f8b\u662f\u5426\u662f\u6307\u5b9a\u7c7b\u578b&#xff0c;\u6216\u8005\u8fd9\u4e2a\u7c7b\u578b\u7684\u5b50\u7c7b\u3002\u5982\u679c\u4e00\u4e2a\u5f15\u7528\u53d8\u91cf\u4e3anull&#xff0c;\u90a3\u4e48\u5bf9\u4efb\u4f55instanceof\u7684\u5224\u65ad\u90fd\u4e3afalse\u3002<\/p>\n<p>\u5229\u7528instanceof&#xff0c;\u5728\u5411\u4e0b\u8f6c\u578b\u524d\u53ef\u4ee5\u5148\u5224\u65ad&#xff1a;<\/p>\n<p>Person p &#061; new Student();<br \/>\nif (p instanceof Student) {<br \/>\n    \/\/ \u53ea\u6709\u5224\u65ad\u6210\u529f\u624d\u4f1a\u5411\u4e0b\u8f6c\u578b:<br \/>\n    Student s &#061; (Student) p; \/\/ \u4e00\u5b9a\u4f1a\u6210\u529f<br \/>\n}<\/p>\n<p>\u4eceJava 14\u5f00\u59cb&#xff0c;\u5224\u65adinstanceof\u540e&#xff0c;\u53ef\u4ee5\u76f4\u63a5\u8f6c\u578b\u4e3a\u6307\u5b9a\u53d8\u91cf&#xff0c;\u907f\u514d\u518d\u6b21\u5f3a\u5236\u8f6c\u578b\u3002\u4f8b\u5982&#xff0c;\u5bf9\u4e8e\u4ee5\u4e0b\u4ee3\u7801&#xff1a;<\/p>\n<p>Object obj &#061; &#034;hello&#034;;<br \/>\nif (obj instanceof String) {<br \/>\n    String s &#061; (String) obj;<br \/>\n    System.out.println(s.toUpperCase());<br \/>\n}<\/p>\n<p>\u53ef\u4ee5\u6539\u5199\u5982\u4e0b&#xff1a;<\/p>\n<p>\/\/ instanceof variable:<br \/>\npublic class Main {<br \/>\n    public static void main(String[] args) {<br \/>\n        Object obj &#061; &#034;hello&#034;;<br \/>\n        if (obj instanceof String s) {<br \/>\n            \/\/ \u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u53d8\u91cfs:<br \/>\n            System.out.println(s.toUpperCase());<br \/>\n        }<br \/>\n    }<br \/>\n}<\/p>\n<p>\u8fd9\u79cd\u4f7f\u7528instanceof\u7684\u5199\u6cd5\u66f4\u52a0\u7b80\u6d01\u3002<\/p>\n<h4>\u533a\u5206\u7ee7\u627f\u548c\u7ec4\u5408<\/h4>\n<p>\u5728\u4f7f\u7528\u7ee7\u627f\u65f6&#xff0c;\u6211\u4eec\u8981\u6ce8\u610f\u903b\u8f91\u4e00\u81f4\u6027\u3002<\/p>\n<p>\u8003\u5bdf\u4e0b\u9762\u7684Book\u7c7b&#xff1a;<\/p>\n<p>class Book {<br \/>\n    protected String name;<br \/>\n    public String getName() {&#8230;}<br \/>\n    public void setName(String name) {&#8230;}<br \/>\n}<\/p>\n<p>\u8fd9\u4e2aBook\u7c7b\u4e5f\u6709name\u5b57\u6bb5&#xff0c;\u90a3\u4e48&#xff0c;\u6211\u4eec\u80fd\u4e0d\u80fd\u8ba9Student\u7ee7\u627f\u81eaBook\u5462&#xff1f;<\/p>\n<p>class Student extends Book {<br \/>\n    protected int score;<br \/>\n}<\/p>\n<p>\u663e\u7136&#xff0c;\u4ece\u903b\u8f91\u4e0a\u8bb2&#xff0c;\u8fd9\u662f\u4e0d\u5408\u7406\u7684&#xff0c;Student\u4e0d\u5e94\u8be5\u4eceBook\u7ee7\u627f&#xff0c;\u800c\u5e94\u8be5\u4ecePerson\u7ee7\u627f\u3002<\/p>\n<p>\u7a76\u5176\u539f\u56e0&#xff0c;\u662f\u56e0\u4e3aStudent\u662fPerson\u7684\u4e00\u79cd&#xff0c;\u5b83\u4eec\u662fis\u5173\u7cfb&#xff0c;\u800cStudent\u5e76\u4e0d\u662fBook\u3002\u5b9e\u9645\u4e0aStudent\u548cBook\u7684\u5173\u7cfb\u662fhas\u5173\u7cfb\u3002<\/p>\n<p>\u5177\u6709has\u5173\u7cfb\u4e0d\u5e94\u8be5\u4f7f\u7528\u7ee7\u627f&#xff0c;\u800c\u662f\u4f7f\u7528\u7ec4\u5408&#xff0c;\u5373Student\u53ef\u4ee5\u6301\u6709\u4e00\u4e2aBook\u5b9e\u4f8b&#xff1a;<\/p>\n<p>class Student extends Person {<br \/>\n    protected Book book;<br \/>\n    protected int score;<br \/>\n}<\/p>\n<p>\u56e0\u6b64&#xff0c;\u7ee7\u627f\u662fis\u5173\u7cfb&#xff0c;\u7ec4\u5408\u662fhas\u5173\u7cfb\u3002<\/p>\n<h4>\u5c0f\u7ed3<\/h4>\n<p>\u7ee7\u627f\u662f\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\u7684\u4e00\u79cd\u5f3a\u5927\u7684\u4ee3\u7801\u590d\u7528\u65b9\u5f0f&#xff1b;<\/p>\n<p>Java\u53ea\u5141\u8bb8\u5355\u7ee7\u627f&#xff0c;\u6240\u6709\u7c7b\u6700\u7ec8\u7684\u6839\u7c7b\u662fObject&#xff1b;<\/p>\n<p>protected\u5141\u8bb8\u5b50\u7c7b\u8bbf\u95ee\u7236\u7c7b\u7684\u5b57\u6bb5\u548c\u65b9\u6cd5&#xff1b;<\/p>\n<p>\u5b50\u7c7b\u7684\u6784\u9020\u65b9\u6cd5\u53ef\u4ee5\u901a\u8fc7super()\u8c03\u7528\u7236\u7c7b\u7684\u6784\u9020\u65b9\u6cd5&#xff1b;<\/p>\n<p>\u53ef\u4ee5\u5b89\u5168\u5730\u5411\u4e0a\u8f6c\u578b\u4e3a\u66f4\u62bd\u8c61\u7684\u7c7b\u578b&#xff1b;<\/p>\n<p>\u53ef\u4ee5\u5f3a\u5236\u5411\u4e0b\u8f6c\u578b&#xff0c;\u6700\u597d\u501f\u52a9instanceof\u5224\u65ad&#xff1b;<\/p>\n<p>\u5b50\u7c7b\u548c\u7236\u7c7b\u7684\u5173\u7cfb\u662fis&#xff0c;has\u5173\u7cfb\u4e0d\u80fd\u7528\u7ee7\u627f\u3002<\/p>\n<h4>\u591a\u6001<\/h4>\n<p>\u5728\u7ee7\u627f\u5173\u7cfb\u4e2d&#xff0c;\u5b50\u7c7b\u5982\u679c\u5b9a\u4e49\u4e86\u4e00\u4e2a\u4e0e\u7236\u7c7b\u65b9\u6cd5\u7b7e\u540d\u5b8c\u5168\u76f8\u540c\u7684\u65b9\u6cd5&#xff0c;\u88ab\u79f0\u4e3a\u8986\u5199&#xff08;Override&#xff09;\u3002<\/p>\n<p>\u4f8b\u5982&#xff0c;\u5728Person\u7c7b\u4e2d&#xff0c;\u6211\u4eec\u5b9a\u4e49\u4e86run()\u65b9\u6cd5&#xff1a;<\/p>\n<p>class Person {<br \/>\n    public void run() {<br \/>\n        System.out.println(&#034;Person.run&#034;);<br \/>\n    }<br \/>\n}<\/p>\n<p>\u5728\u5b50\u7c7bStudent\u4e2d&#xff0c;\u8986\u5199\u8fd9\u4e2arun()\u65b9\u6cd5&#xff1a;<\/p>\n<p>class Student extends Person {<br \/>\n    &#064;Override<br \/>\n    public void run() {<br \/>\n        System.out.println(&#034;Student.run&#034;);<br \/>\n    }<br \/>\n}<\/p>\n<p>Override\u548cOverload\u4e0d\u540c\u7684\u662f&#xff0c;\u5982\u679c\u65b9\u6cd5\u7b7e\u540d\u4e0d\u540c&#xff0c;\u5c31\u662fOverload&#xff0c;Overload\u65b9\u6cd5\u662f\u4e00\u4e2a\u65b0\u65b9\u6cd5&#xff1b;\u5982\u679c\u65b9\u6cd5\u7b7e\u540d\u76f8\u540c&#xff0c;\u5e76\u4e14\u8fd4\u56de\u503c\u4e5f\u76f8\u540c&#xff0c;\u5c31\u662fOverride\u3002<\/p>\n<p>\u00a0\u6ce8\u610f<\/p>\n<p>\u65b9\u6cd5\u540d\u76f8\u540c&#xff0c;\u65b9\u6cd5\u53c2\u6570\u76f8\u540c&#xff0c;\u4f46\u65b9\u6cd5\u8fd4\u56de\u503c\u4e0d\u540c&#xff0c;\u4e5f\u662f\u4e0d\u540c\u7684\u65b9\u6cd5\u3002\u5728Java\u7a0b\u5e8f\u4e2d&#xff0c;\u51fa\u73b0\u8fd9\u79cd\u60c5\u51b5&#xff0c;\u7f16\u8bd1\u5668\u4f1a\u62a5\u9519\u3002<\/p>\n<p>class Person {<br \/>\n    public void run() { \u2026 }<br \/>\n}<\/p>\n<p>class Student extends Person {<br \/>\n    \/\/ \u4e0d\u662fOverride&#xff0c;\u56e0\u4e3a\u53c2\u6570\u4e0d\u540c:<br \/>\n    public void run(String s) { \u2026 }<br \/>\n    \/\/ \u4e0d\u662fOverride&#xff0c;\u56e0\u4e3a\u8fd4\u56de\u503c\u4e0d\u540c:<br \/>\n    public int run() { \u2026 }<br \/>\n}<\/p>\n<p>\u52a0\u4e0a&#064;Override\u53ef\u4ee5\u8ba9\u7f16\u8bd1\u5668\u5e2e\u52a9\u68c0\u67e5\u662f\u5426\u8fdb\u884c\u4e86\u6b63\u786e\u7684\u8986\u5199\u3002\u5e0c\u671b\u8fdb\u884c\u8986\u5199&#xff0c;\u4f46\u662f\u4e0d\u5c0f\u5fc3\u5199\u9519\u4e86\u65b9\u6cd5\u7b7e\u540d&#xff0c;\u7f16\u8bd1\u5668\u4f1a\u62a5\u9519\u3002<\/p>\n<p>\/\/ override<br \/>\npublic class Main {<br \/>\n    public static void main(String[] args) {<br \/>\n    }<br \/>\n}<\/p>\n<p>class Person {<br \/>\n    public void run() {}<br \/>\n}<\/p>\n<p>public class Student extends Person {<br \/>\n    &#064;Override \/\/ Compile error!<br \/>\n    public void run(String s) {}<br \/>\n}<\/p>\n<p>\u4f46\u662f&#064;Override\u4e0d\u662f\u5fc5\u9700\u7684\u3002<\/p>\n<p>\u5728\u4e0a\u4e00\u8282\u4e2d&#xff0c;\u6211\u4eec\u5df2\u7ecf\u77e5\u9053&#xff0c;\u5f15\u7528\u53d8\u91cf\u7684\u58f0\u660e\u7c7b\u578b\u53ef\u80fd\u4e0e\u5176\u5b9e\u9645\u7c7b\u578b\u4e0d\u7b26&#xff0c;\u4f8b\u5982&#xff1a;<\/p>\n<p>Person p &#061; new Student();<\/p>\n<p>\u73b0\u5728&#xff0c;\u6211\u4eec\u8003\u8651\u4e00\u79cd\u60c5\u51b5&#xff0c;\u5982\u679c\u5b50\u7c7b\u8986\u5199\u4e86\u7236\u7c7b\u7684\u65b9\u6cd5&#xff1a;<\/p>\n<p>\/\/ override<br \/>\npublic class Main {<br \/>\n    public static void main(String[] args) {<br \/>\n        Person p &#061; new Student();<br \/>\n        p.run(); \/\/ \u5e94\u8be5\u6253\u5370Person.run\u8fd8\u662fStudent.run?<br \/>\n    }<br \/>\n}<\/p>\n<p>class Person {<br \/>\n    public void run() {<br \/>\n        System.out.println(&#034;Person.run&#034;);<br \/>\n    }<br \/>\n}<\/p>\n<p>class Student extends Person {<br \/>\n    &#064;Override<br \/>\n    public void run() {<br \/>\n        System.out.println(&#034;Student.run&#034;);<br \/>\n    }<br \/>\n}<\/p>\n<p>\u90a3\u4e48&#xff0c;\u4e00\u4e2a\u5b9e\u9645\u7c7b\u578b\u4e3aStudent&#xff0c;\u5f15\u7528\u7c7b\u578b\u4e3aPerson\u7684\u53d8\u91cf&#xff0c;\u8c03\u7528\u5176run()\u65b9\u6cd5&#xff0c;\u8c03\u7528\u7684\u662fPerson\u8fd8\u662fStudent\u7684run()\u65b9\u6cd5&#xff1f;<\/p>\n<p>\u8fd0\u884c\u4e00\u4e0b\u4e0a\u9762\u7684\u4ee3\u7801\u5c31\u53ef\u4ee5\u77e5\u9053&#xff0c;\u5b9e\u9645\u4e0a\u8c03\u7528\u7684\u65b9\u6cd5\u662fStudent\u7684run()\u65b9\u6cd5\u3002\u56e0\u6b64\u53ef\u5f97\u51fa\u7ed3\u8bba&#xff1a;<\/p>\n<p>Java\u7684\u5b9e\u4f8b\u65b9\u6cd5\u8c03\u7528\u662f\u57fa\u4e8e\u8fd0\u884c\u65f6\u7684\u5b9e\u9645\u7c7b\u578b\u7684\u52a8\u6001\u8c03\u7528&#xff0c;\u800c\u975e\u53d8\u91cf\u7684\u58f0\u660e\u7c7b\u578b\u3002<\/p>\n<p>\u8fd9\u4e2a\u975e\u5e38\u91cd\u8981\u7684\u7279\u6027\u5728\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\u4e2d\u79f0\u4e4b\u4e3a\u591a\u6001\u3002\u5b83\u7684\u82f1\u6587\u62fc\u5199\u975e\u5e38\u590d\u6742&#xff1a;Polymorphic\u3002<\/p>\n<h4>\u591a\u6001<\/h4>\n<p>\u591a\u6001\u662f\u6307&#xff0c;\u9488\u5bf9\u67d0\u4e2a\u7c7b\u578b\u7684\u65b9\u6cd5\u8c03\u7528&#xff0c;\u5176\u771f\u6b63\u6267\u884c\u7684\u65b9\u6cd5\u53d6\u51b3\u4e8e\u8fd0\u884c\u65f6\u671f\u5b9e\u9645\u7c7b\u578b\u7684\u65b9\u6cd5\u3002\u4f8b\u5982&#xff1a;<\/p>\n<p>Person p &#061; new Student();<br \/>\np.run(); \/\/ \u65e0\u6cd5\u786e\u5b9a\u8fd0\u884c\u65f6\u7a76\u7adf\u8c03\u7528\u54ea\u4e2arun()\u65b9\u6cd5<\/p>\n<p>\u6709\u540c\u5b66\u4f1a\u8bf4&#xff0c;\u4ece\u4e0a\u9762\u7684\u4ee3\u7801\u4e00\u770b\u5c31\u660e\u767d&#xff0c;\u80af\u5b9a\u8c03\u7528\u7684\u662fStudent\u7684run()\u65b9\u6cd5\u554a\u3002<\/p>\n<p>\u4f46\u662f&#xff0c;\u5047\u8bbe\u6211\u4eec\u7f16\u5199\u8fd9\u6837\u4e00\u4e2a\u65b9\u6cd5&#xff1a;<\/p>\n<p>public void runTwice(Person p) {<br \/>\n    p.run();<br \/>\n    p.run();<br \/>\n}<\/p>\n<p>\u5b83\u4f20\u5165\u7684\u53c2\u6570\u7c7b\u578b\u662fPerson&#xff0c;\u6211\u4eec\u662f\u65e0\u6cd5\u77e5\u9053\u4f20\u5165\u7684\u53c2\u6570\u5b9e\u9645\u7c7b\u578b\u7a76\u7adf\u662fPerson&#xff0c;\u8fd8\u662fStudent&#xff0c;\u8fd8\u662fPerson\u7684\u5176\u4ed6\u5b50\u7c7b\u4f8b\u5982Teacher&#xff0c;\u56e0\u6b64&#xff0c;\u4e5f\u65e0\u6cd5\u786e\u5b9a\u8c03\u7528\u7684\u662f\u4e0d\u662fPerson\u7c7b\u5b9a\u4e49\u7684run()\u65b9\u6cd5\u3002<\/p>\n<p>\u6240\u4ee5&#xff0c;\u591a\u6001\u7684\u7279\u6027\u5c31\u662f&#xff0c;\u8fd0\u884c\u671f\u624d\u80fd\u52a8\u6001\u51b3\u5b9a\u8c03\u7528\u7684\u5b50\u7c7b\u65b9\u6cd5\u3002\u5bf9\u67d0\u4e2a\u7c7b\u578b\u8c03\u7528\u67d0\u4e2a\u65b9\u6cd5&#xff0c;\u6267\u884c\u7684\u5b9e\u9645\u65b9\u6cd5\u53ef\u80fd\u662f\u67d0\u4e2a\u5b50\u7c7b\u7684\u8986\u5199\u65b9\u6cd5\u3002\u8fd9\u79cd\u4e0d\u786e\u5b9a\u6027\u7684\u65b9\u6cd5\u8c03\u7528&#xff0c;\u7a76\u7adf\u6709\u4ec0\u4e48\u4f5c\u7528&#xff1f;<\/p>\n<p>\u6211\u4eec\u8fd8\u662f\u6765\u4e3e\u4f8b\u5b50\u3002<\/p>\n<p>\u5047\u8bbe\u6211\u4eec\u5b9a\u4e49\u4e00\u79cd\u6536\u5165&#xff0c;\u9700\u8981\u7ed9\u5b83\u62a5\u7a0e&#xff0c;\u90a3\u4e48\u5148\u5b9a\u4e49\u4e00\u4e2aIncome\u7c7b&#xff1a;<\/p>\n<p>class Income {<br \/>\n    protected double income;<br \/>\n    public double getTax() {<br \/>\n        return income * 0.1; \/\/ \u7a0e\u738710%<br \/>\n    }<br \/>\n}<\/p>\n<p>\u5bf9\u4e8e\u5de5\u8d44\u6536\u5165&#xff0c;\u53ef\u4ee5\u51cf\u53bb\u4e00\u4e2a\u57fa\u6570&#xff0c;\u90a3\u4e48\u6211\u4eec\u53ef\u4ee5\u4eceIncome\u6d3e\u751f\u51faSalaryIncome&#xff0c;\u5e76\u8986\u5199getTax()&#xff1a;<\/p>\n<p>class Salary extends Income {<br \/>\n    &#064;Override<br \/>\n    public double getTax() {<br \/>\n        if (income &lt;&#061; 5000) {<br \/>\n            return 0;<br \/>\n        }<br \/>\n        return (income &#8211; 5000) * 0.2;<br \/>\n    }<br \/>\n}<\/p>\n<p>\u5982\u679c\u4f60\u4eab\u53d7\u56fd\u52a1\u9662\u7279\u6b8a\u6d25\u8d34&#xff0c;\u90a3\u4e48\u6309\u7167\u89c4\u5b9a&#xff0c;\u53ef\u4ee5\u5168\u90e8\u514d\u7a0e&#xff1a;<\/p>\n<p>class StateCouncilSpecialAllowance extends Income {<br \/>\n    &#064;Override<br \/>\n    public double getTax() {<br \/>\n        return 0;<br \/>\n    }<br \/>\n}<\/p>\n<p>\u73b0\u5728&#xff0c;\u6211\u4eec\u8981\u7f16\u5199\u4e00\u4e2a\u62a5\u7a0e\u7684\u8d22\u52a1\u8f6f\u4ef6&#xff0c;\u5bf9\u4e8e\u4e00\u4e2a\u4eba\u7684\u6240\u6709\u6536\u5165\u8fdb\u884c\u62a5\u7a0e&#xff0c;\u53ef\u4ee5\u8fd9\u4e48\u5199&#xff1a;<\/p>\n<p>public double totalTax(Income&#8230; incomes) {<br \/>\n    double total &#061; 0;<br \/>\n    for (Income income: incomes) {<br \/>\n        total &#061; total &#043; income.getTax();<br \/>\n    }<br \/>\n    return total;<br \/>\n}<\/p>\n<p>\u6765\u8bd5\u4e00\u4e0b&#xff1a;<\/p>\n<p>\/\/ Polymorphic<br \/>\npublic class Main {<br \/>\n    public static void main(String[] args) {<br \/>\n        \/\/ \u7ed9\u4e00\u4e2a\u6709\u666e\u901a\u6536\u5165\u3001\u5de5\u8d44\u6536\u5165\u548c\u4eab\u53d7\u56fd\u52a1\u9662\u7279\u6b8a\u6d25\u8d34\u7684\u5c0f\u4f19\u4f34\u7b97\u7a0e:<br \/>\n        Income[] incomes &#061; new Income[] {<br \/>\n            new Income(3000),<br \/>\n            new Salary(7500),<br \/>\n            new StateCouncilSpecialAllowance(15000)<br \/>\n        };<br \/>\n        System.out.println(totalTax(incomes));<br \/>\n    }<\/p>\n<p>    public static double totalTax(Income&#8230; incomes) {<br \/>\n        double total &#061; 0;<br \/>\n        for (Income income: incomes) {<br \/>\n            total &#061; total &#043; income.getTax();<br \/>\n        }<br \/>\n        return total;<br \/>\n    }<br \/>\n}<\/p>\n<p>class Income {<br \/>\n    protected double income;<\/p>\n<p>    public Income(double income) {<br \/>\n        this.income &#061; income;<br \/>\n    }<\/p>\n<p>    public double getTax() {<br \/>\n        return income * 0.1; \/\/ \u7a0e\u738710%<br \/>\n    }<br \/>\n}<\/p>\n<p>class Salary extends Income {<br \/>\n    public Salary(double income) {<br \/>\n        super(income);<br \/>\n    }<\/p>\n<p>    &#064;Override<br \/>\n    public double getTax() {<br \/>\n        if (income &lt;&#061; 5000) {<br \/>\n            return 0;<br \/>\n        }<br \/>\n        return (income &#8211; 5000) * 0.2;<br \/>\n    }<br \/>\n}<\/p>\n<p>class StateCouncilSpecialAllowance extends Income {<br \/>\n    public StateCouncilSpecialAllowance(double income) {<br \/>\n        super(income);<br \/>\n    }<\/p>\n<p>    &#064;Override<br \/>\n    public double getTax() {<br \/>\n        return 0;<br \/>\n    }<br \/>\n}<\/p>\n<p>\u89c2\u5bdftotalTax()\u65b9\u6cd5&#xff1a;\u5229\u7528\u591a\u6001&#xff0c;totalTax()\u65b9\u6cd5\u53ea\u9700\u8981\u548cIncome\u6253\u4ea4\u9053&#xff0c;\u5b83\u5b8c\u5168\u4e0d\u9700\u8981\u77e5\u9053Salary\u548cStateCouncilSpecialAllowance\u7684\u5b58\u5728&#xff0c;\u5c31\u53ef\u4ee5\u6b63\u786e\u8ba1\u7b97\u51fa\u603b\u7684\u7a0e\u3002\u5982\u679c\u6211\u4eec\u8981\u65b0\u589e\u4e00\u79cd\u7a3f\u8d39\u6536\u5165&#xff0c;\u53ea\u9700\u8981\u4eceIncome\u6d3e\u751f&#xff0c;\u7136\u540e\u6b63\u786e\u8986\u5199getTax()\u65b9\u6cd5\u5c31\u53ef\u4ee5\u3002\u628a\u65b0\u7684\u7c7b\u578b\u4f20\u5165totalTax()&#xff0c;\u4e0d\u9700\u8981\u4fee\u6539\u4efb\u4f55\u4ee3\u7801\u3002<\/p>\n<p>\u53ef\u89c1&#xff0c;\u591a\u6001\u5177\u6709\u4e00\u4e2a\u975e\u5e38\u5f3a\u5927\u7684\u529f\u80fd&#xff0c;\u5c31\u662f\u5141\u8bb8\u6dfb\u52a0\u66f4\u591a\u7c7b\u578b\u7684\u5b50\u7c7b\u5b9e\u73b0\u529f\u80fd\u6269\u5c55&#xff0c;\u5374\u4e0d\u9700\u8981\u4fee\u6539\u57fa\u4e8e\u7236\u7c7b\u7684\u4ee3\u7801\u3002<\/p>\n<h4>\u8986\u5199Object\u65b9\u6cd5<\/h4>\n<p>\u56e0\u4e3a\u6240\u6709\u7684class\u6700\u7ec8\u90fd\u7ee7\u627f\u81eaObject&#xff0c;\u800cObject\u5b9a\u4e49\u4e86\u51e0\u4e2a\u91cd\u8981\u7684\u65b9\u6cd5&#xff1a;<\/p>\n<ul>\n<li>toString()&#xff1a;\u628ainstance\u8f93\u51fa\u4e3aString&#xff1b;<\/li>\n<li>equals()&#xff1a;\u5224\u65ad\u4e24\u4e2ainstance\u662f\u5426\u903b\u8f91\u76f8\u7b49&#xff1b;<\/li>\n<li>hashCode()&#xff1a;\u8ba1\u7b97\u4e00\u4e2ainstance\u7684\u54c8\u5e0c\u503c\u3002<\/li>\n<\/ul>\n<p>\u5728\u5fc5\u8981\u7684\u60c5\u51b5\u4e0b&#xff0c;\u6211\u4eec\u53ef\u4ee5\u8986\u5199Object\u7684\u8fd9\u51e0\u4e2a\u65b9\u6cd5\u3002\u4f8b\u5982&#xff1a;<\/p>\n<p>class Person {<br \/>\n    &#8230;<br \/>\n    \/\/ \u663e\u793a\u66f4\u6709\u610f\u4e49\u7684\u5b57\u7b26\u4e32:<br \/>\n    &#064;Override<br \/>\n    public String toString() {<br \/>\n        return &#034;Person:name&#061;&#034; &#043; name;<br \/>\n    }<\/p>\n<p>    \/\/ \u6bd4\u8f83\u662f\u5426\u76f8\u7b49:<br \/>\n    &#064;Override<br \/>\n    public boolean equals(Object o) {<br \/>\n        \/\/ \u5f53\u4e14\u4ec5\u5f53o\u4e3aPerson\u7c7b\u578b:<br \/>\n        if (o instanceof Person) {<br \/>\n            Person p &#061; (Person) o;<br \/>\n            \/\/ \u5e76\u4e14name\u5b57\u6bb5\u76f8\u540c\u65f6&#xff0c;\u8fd4\u56detrue:<br \/>\n            return this.name.equals(p.name);<br \/>\n        }<br \/>\n        return false;<br \/>\n    }<\/p>\n<p>    \/\/ \u8ba1\u7b97hash:<br \/>\n    &#064;Override<br \/>\n    public int hashCode() {<br \/>\n        return this.name.hashCode();<br \/>\n    }<br \/>\n}<\/p>\n<h4>\u8c03\u7528super<\/h4>\n<p>\u5728\u5b50\u7c7b\u7684\u8986\u5199\u65b9\u6cd5\u4e2d&#xff0c;\u5982\u679c\u8981\u8c03\u7528\u7236\u7c7b\u7684\u88ab\u8986\u5199\u7684\u65b9\u6cd5&#xff0c;\u53ef\u4ee5\u901a\u8fc7super\u6765\u8c03\u7528\u3002\u4f8b\u5982&#xff1a;<\/p>\n<p>class Person {<br \/>\n    protected String name;<br \/>\n    public String hello() {<br \/>\n        return &#034;Hello, &#034; &#043; name;<br \/>\n    }<br \/>\n}<\/p>\n<p>class Student extends Person {<br \/>\n    &#064;Override<br \/>\n    public String hello() {<br \/>\n        \/\/ \u8c03\u7528\u7236\u7c7b\u7684hello()\u65b9\u6cd5:<br \/>\n        return super.hello() &#043; &#034;!&#034;;<br \/>\n    }<br \/>\n}<\/p>\n<h4>final<\/h4>\n<p>\u7ee7\u627f\u53ef\u4ee5\u5141\u8bb8\u5b50\u7c7b\u8986\u5199\u7236\u7c7b\u7684\u65b9\u6cd5\u3002\u5982\u679c\u4e00\u4e2a\u7236\u7c7b\u4e0d\u5141\u8bb8\u5b50\u7c7b\u5bf9\u5b83\u7684\u67d0\u4e2a\u65b9\u6cd5\u8fdb\u884c\u8986\u5199&#xff0c;\u53ef\u4ee5\u628a\u8be5\u65b9\u6cd5\u6807\u8bb0\u4e3afinal\u3002\u7528final\u4fee\u9970\u7684\u65b9\u6cd5\u4e0d\u80fd\u88abOverride&#xff1a;<\/p>\n<p>class Person {<br \/>\n    protected String name;<br \/>\n    public final String hello() {<br \/>\n        return &#034;Hello, &#034; &#043; name;<br \/>\n    }<br \/>\n}<\/p>\n<p>class Student extends Person {<br \/>\n    \/\/ compile error: \u4e0d\u5141\u8bb8\u8986\u5199<br \/>\n    &#064;Override<br \/>\n    public String hello() {<br \/>\n    }<br \/>\n}<\/p>\n<p>\u5982\u679c\u4e00\u4e2a\u7c7b\u4e0d\u5e0c\u671b\u4efb\u4f55\u5176\u4ed6\u7c7b\u7ee7\u627f\u81ea\u5b83&#xff0c;\u90a3\u4e48\u53ef\u4ee5\u628a\u8fd9\u4e2a\u7c7b\u672c\u8eab\u6807\u8bb0\u4e3afinal\u3002\u7528final\u4fee\u9970\u7684\u7c7b\u4e0d\u80fd\u88ab\u7ee7\u627f&#xff1a;<\/p>\n<p>final class Person {<br \/>\n    protected String name;<br \/>\n}<\/p>\n<p>\/\/ compile error: \u4e0d\u5141\u8bb8\u7ee7\u627f\u81eaPerson<br \/>\nclass Student extends Person {<br \/>\n}<\/p>\n<p>\u5bf9\u4e8e\u4e00\u4e2a\u7c7b\u7684\u5b9e\u4f8b\u5b57\u6bb5&#xff0c;\u540c\u6837\u53ef\u4ee5\u7528final\u4fee\u9970\u3002\u7528final\u4fee\u9970\u7684\u5b57\u6bb5\u5728\u521d\u59cb\u5316\u540e\u4e0d\u80fd\u88ab\u4fee\u6539\u3002\u4f8b\u5982&#xff1a;<\/p>\n<p>class Person {<br \/>\n    public final String name &#061; &#034;Unamed&#034;;<br \/>\n}<\/p>\n<p>\u5bf9final\u5b57\u6bb5\u91cd\u65b0\u8d4b\u503c\u4f1a\u62a5\u9519&#xff1a;<\/p>\n<p>Person p &#061; new Person();<br \/>\np.name &#061; &#034;New Name&#034;; \/\/ compile error!<\/p>\n<p>\u53ef\u4ee5\u5728\u6784\u9020\u65b9\u6cd5\u4e2d\u521d\u59cb\u5316final\u5b57\u6bb5&#xff1a;<\/p>\n<p>class Person {<br \/>\n    public final String name;<br \/>\n    public Person(String name) {<br \/>\n        this.name &#061; name;<br \/>\n    }<br \/>\n}<\/p>\n<p>\u8fd9\u79cd\u65b9\u6cd5\u66f4\u4e3a\u5e38\u7528&#xff0c;\u56e0\u4e3a\u53ef\u4ee5\u4fdd\u8bc1\u5b9e\u4f8b\u4e00\u65e6\u521b\u5efa&#xff0c;\u5176final\u5b57\u6bb5\u5c31\u4e0d\u53ef\u4fee\u6539\u3002<\/p>\n<h4>\u5c0f\u7ed3<\/h4>\n<p>\u5b50\u7c7b\u53ef\u4ee5\u8986\u5199\u7236\u7c7b\u7684\u65b9\u6cd5&#xff08;Override&#xff09;&#xff0c;\u8986\u5199\u5728\u5b50\u7c7b\u4e2d\u6539\u53d8\u4e86\u7236\u7c7b\u65b9\u6cd5\u7684\u884c\u4e3a&#xff1b;<\/p>\n<p>Java\u7684\u65b9\u6cd5\u8c03\u7528\u603b\u662f\u4f5c\u7528\u4e8e\u8fd0\u884c\u671f\u5bf9\u8c61\u7684\u5b9e\u9645\u7c7b\u578b&#xff0c;\u8fd9\u79cd\u884c\u4e3a\u79f0\u4e3a\u591a\u6001&#xff1b;<\/p>\n<p>final\u4fee\u9970\u7b26\u6709\u591a\u79cd\u4f5c\u7528&#xff1a;<\/p>\n<ul>\n<li>final\u4fee\u9970\u7684\u65b9\u6cd5\u53ef\u4ee5\u963b\u6b62\u88ab\u8986\u5199&#xff1b;<\/li>\n<li>final\u4fee\u9970\u7684class\u53ef\u4ee5\u963b\u6b62\u88ab\u7ee7\u627f&#xff1b;<\/li>\n<li>final\u4fee\u9970\u7684field\u5fc5\u987b\u5728\u521b\u5efa\u5bf9\u8c61\u65f6\u521d\u59cb\u5316&#xff0c;\u968f\u540e\u4e0d\u53ef\u4fee\u6539\u3002<\/li>\n<\/ul>\n<h2>\u4e09\u6700\u540e\u4e00\u8bed<\/h2>\n<p>\u8fd9\u4e24\u90e8\u5206\u7684\u5185\u5bb9\u8fd8\u662f\u5f88\u96be\u7406\u89e3\u7684&#xff0c;\u4f46\u662f\u597d\u5728\u5199\u7684\u8db3\u591f\u8be6\u7ec6&#xff0c;\u6240\u4ee5\u5927\u5bb6\u53ef\u4ee5\u53cd\u590d\u591a\u770b\u51e0\u6b21&#xff0c;\u81ea\u5df1\u8fd0\u884c\u4e00\u4e0b\u3002<\/p>\n<p>\u9762\u5411\u5927\u6d77&#xff0c;\u6625\u6696\u82b1\u5f00\u3002<\/p>\n<p><span style=\"color:#ff9900\">\u611f\u8c22\u89c2\u770b&#xff0c;\u5171\u52c9&#xff01;&#xff01;<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u524d\u8a00\u4eca\u5929\u4e0d\u77e5\u9053\u54ea\u6765\u7684\u6597\u5fd7&#xff0c;\u611f\u89c9\u72b6\u6001\u5728\u56de\u5f52&#xff0c;\u6240\u6709\u591a\u5199\u4e00\u70b9&#xff0c;\u8fd9\u6b21\u7684\u5185\u5bb9\u6211\u611f\u89c9\u662f\u5f88\u91cd\u8981\u7684\u3002\u5927\u5bb6\u4e00\u8d77\u52aa\u529b\u5427\u3002\u4e8c\u4e3b\u8981\u5185\u5bb9\u7ee7\u627f\u5728\u524d\u9762\u7684\u7ae0\u8282\u4e2d&#xff0c;\u6211\u4eec\u5df2\u7ecf\u5b9a\u4e49\u4e86Person\u7c7b&#xff1a;class Person {private String name;private int age;public String getName() {&#8230;}public void setName(String name) {&#8230;}public <\/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,729],"topic":[],"class_list":["post-69852","post","type-post","status-publish","format-standard","hentry","category-server","tag-java","tag-729"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u84dd\u6865\u676fJAVA-\u542f\u8499\u4e4b\u8def\uff08\u4e03\uff09\u7ee7\u627f\u591a\u6001 - \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\/69852.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u84dd\u6865\u676fJAVA-\u542f\u8499\u4e4b\u8def\uff08\u4e03\uff09\u7ee7\u627f\u591a\u6001 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u4e00\u524d\u8a00\u4eca\u5929\u4e0d\u77e5\u9053\u54ea\u6765\u7684\u6597\u5fd7&#xff0c;\u611f\u89c9\u72b6\u6001\u5728\u56de\u5f52&#xff0c;\u6240\u6709\u591a\u5199\u4e00\u70b9&#xff0c;\u8fd9\u6b21\u7684\u5185\u5bb9\u6211\u611f\u89c9\u662f\u5f88\u91cd\u8981\u7684\u3002\u5927\u5bb6\u4e00\u8d77\u52aa\u529b\u5427\u3002\u4e8c\u4e3b\u8981\u5185\u5bb9\u7ee7\u627f\u5728\u524d\u9762\u7684\u7ae0\u8282\u4e2d&#xff0c;\u6211\u4eec\u5df2\u7ecf\u5b9a\u4e49\u4e86Person\u7c7b&#xff1a;class Person {private String name;private int age;public String getName() {...}public void setName(String name) {...}public\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/69852.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-01-31T21:42:14+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=\"9 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/69852.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/69852.html\",\"name\":\"\u84dd\u6865\u676fJAVA-\u542f\u8499\u4e4b\u8def\uff08\u4e03\uff09\u7ee7\u627f\u591a\u6001 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-01-31T21:42:14+00:00\",\"dateModified\":\"2026-01-31T21:42:14+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/69852.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/69852.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/69852.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u84dd\u6865\u676fJAVA--\u542f\u8499\u4e4b\u8def\uff08\u4e03\uff09\u7ee7\u627f\u591a\u6001\"}]},{\"@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":"\u84dd\u6865\u676fJAVA-\u542f\u8499\u4e4b\u8def\uff08\u4e03\uff09\u7ee7\u627f\u591a\u6001 - \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\/69852.html","og_locale":"zh_CN","og_type":"article","og_title":"\u84dd\u6865\u676fJAVA-\u542f\u8499\u4e4b\u8def\uff08\u4e03\uff09\u7ee7\u627f\u591a\u6001 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u4e00\u524d\u8a00\u4eca\u5929\u4e0d\u77e5\u9053\u54ea\u6765\u7684\u6597\u5fd7&#xff0c;\u611f\u89c9\u72b6\u6001\u5728\u56de\u5f52&#xff0c;\u6240\u6709\u591a\u5199\u4e00\u70b9&#xff0c;\u8fd9\u6b21\u7684\u5185\u5bb9\u6211\u611f\u89c9\u662f\u5f88\u91cd\u8981\u7684\u3002\u5927\u5bb6\u4e00\u8d77\u52aa\u529b\u5427\u3002\u4e8c\u4e3b\u8981\u5185\u5bb9\u7ee7\u627f\u5728\u524d\u9762\u7684\u7ae0\u8282\u4e2d&#xff0c;\u6211\u4eec\u5df2\u7ecf\u5b9a\u4e49\u4e86Person\u7c7b&#xff1a;class Person {private String name;private int age;public String getName() {...}public void setName(String name) {...}public","og_url":"https:\/\/www.wsisp.com\/helps\/69852.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-01-31T21:42:14+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"9 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/69852.html","url":"https:\/\/www.wsisp.com\/helps\/69852.html","name":"\u84dd\u6865\u676fJAVA-\u542f\u8499\u4e4b\u8def\uff08\u4e03\uff09\u7ee7\u627f\u591a\u6001 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-01-31T21:42:14+00:00","dateModified":"2026-01-31T21:42:14+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/69852.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/69852.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/69852.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u84dd\u6865\u676fJAVA--\u542f\u8499\u4e4b\u8def\uff08\u4e03\uff09\u7ee7\u627f\u591a\u6001"}]},{"@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\/69852","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=69852"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/69852\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=69852"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=69852"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=69852"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=69852"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}