{"id":215,"date":"2023-11-14T09:41:45","date_gmt":"2023-11-14T01:41:45","guid":{"rendered":"http:\/\/ericw.top\/?p=215"},"modified":"2023-11-14T09:45:04","modified_gmt":"2023-11-14T01:45:04","slug":"215","status":"publish","type":"post","link":"http:\/\/ericw.top\/?p=215","title":{"rendered":"\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b OOP"},"content":{"rendered":"<h1 id=\"toc-0\">\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\u7684\u827a\u672f<\/h1>\n<p><strong>\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b<\/strong>\uff08Object-Oriented Programming\uff0cOOP\uff09\u662fJAVA\u4e2d\u91cd\u8981\u7684\u6982\u5ff5\u3002<\/p>\n<p>Java\u662f\u4e00\u79cd\u9762\u5411\u5bf9\u8c61\u7684\u7f16\u7a0b\u8bed\u8a00\uff0c\u8fd9\u610f\u5473\u7740\u5b83\u7684\u7f16\u7a0b\u8303\u5f0f\u57fa\u4e8e\u5bf9\u8c61\u3001\u7c7b\u548c\u7ee7\u627f\u3002<\/p>\n<h2 id=\"toc-1\">\u4ec0\u4e48\u662f\u5bf9\u8c61<\/h2>\n<p>\u9996\u5148\u6211\u4eec\u8981\u77e5\u9053\u4ec0\u4e48\u662f\u5bf9\u8c61\uff1f<\/p>\n<p><strong>\u5bf9\u8c61\u5c31\u662f\u9762\u5411\u5bf9\u8c61\u7a0b\u5e8f\u8bbe\u8ba1\u7684\u6838\u5fc3<\/strong>\u3002<\/p>\n<p>\u5728\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\u4e2d\uff0c\u5bf9\u8c61\u662f\u7a0b\u5e8f\u4e2d\u7684\u57fa\u672c\u6784\u5efa\u5757\u3002<\/p>\n<p>\u5bf9\u8c61\u5c31\u662f\u73b0\u5b9e\u4e16\u754c\u4e2d\u7684\u5b9e\u4f53\u548c\u6982\u5ff5\uff0c\u5e76\u5177\u6709\u72b6\u6001\uff08\u5c5e\u6027\uff09\u548c\u884c\u4e3a\uff08\u65b9\u6cd5\uff09\u3002<\/p>\n<p><strong>\u5bf9\u8c61\u5177\u6709\u5c5e\u6027\u548c\u65b9\u6cd5\uff0c\u5bf9\u8c61\u5c31\u662f\u6570\u636e\u548c\u64cd\u4f5c\u6570\u636e\u7684\u7ec4\u5408<\/strong><\/p>\n<p><em>\u5047\u8bbe\u6211\u4eec\u8981\u6a21\u62df\u4e00\u4e2a\u94f6\u884c\u8d26\u6237\u7cfb\u7edf\uff0c\u6bcf\u4e2a\u8d26\u6237\u90fd\u662f\u4e00\u4e2a\u5bf9\u8c61\u3002\u6bcf\u4e2a\u8d26\u6237\u5bf9\u8c61\u90fd\u6709\u4ee5\u4e0b\u5c5e\u6027\uff1a<\/em><\/p>\n<ul>\n<li><strong><em>\u8d26\u6237\u6301\u6709\u8005\u7684\u59d3\u540d<\/em><\/strong><\/li>\n<li><strong><em>\u8d26\u6237\u53f7\u7801<\/em><\/strong><\/li>\n<li><strong><em>\u5f53\u524d\u4f59\u989d<\/em><\/strong><\/li>\n<\/ul>\n<p><em>\u8fd9\u4e9b\u5c5e\u6027\u63cf\u8ff0\u4e86\u8d26\u6237\u5bf9\u8c61\u7684\u72b6\u6001\u3002\u6b64\u5916\uff0c\u8d26\u6237\u5bf9\u8c61\u8fd8\u53ef\u4ee5\u6267\u884c\u4ee5\u4e0b\u64cd\u4f5c\uff08\u65b9\u6cd5\uff09\uff1a<\/em><\/p>\n<ul>\n<li><strong><em>\u5b58\u6b3e<\/em><\/strong><\/li>\n<li><strong><em>\u53d6\u6b3e<\/em><\/strong><\/li>\n<li><strong><em>\u67e5\u8be2\u4f59\u989d<\/em><\/strong><\/li>\n<\/ul>\n<p>\u8fd9\u4e9b\u64cd\u4f5c\u63cf\u8ff0\u4e86\u8d26\u6237\u5bf9\u8c61\u7684\u884c\u4e3a\u3002\u56e0\u6b64\uff0c\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u94f6\u884c\u8d26\u6237\u5c31\u662f\u4e00\u4e2a\u5bf9\u8c61\uff0c\u5b83\u6709\u5c5e\u6027\u548c\u65b9\u6cd5\u3002<\/p>\n<h2 id=\"toc-2\">\u4ec0\u4e48\u662f\u7c7b<\/h2>\n<p>\u7c7b\u662f\u5bf9\u8c61\u7684\u6a21\u677f\u6216\u84dd\u56fe\u3002\u5b83\u5b9a\u4e49\u4e86<strong>\u5bf9\u8c61\u7684\u5c5e\u6027\u548c\u65b9\u6cd5<\/strong>\u3002<\/p>\n<p>\u5728Java\u4e2d\uff0c<strong>\u7c7b\u662f\u521b\u5efa\u5bf9\u8c61\u7684\u57fa\u7840<\/strong>\u3002\u5bf9\u8c61\u662f\u7c7b\u7684\u5b9e\u4f8b\uff0c\u800c\u7c7b\u5b9a\u4e49\u4e86\u5bf9\u8c61\u7684\u7ed3\u6784\u548c\u884c\u4e3a\u3002<\/p>\n<p><strong>\u7c7b\u662fJava\u4e2d\u7528\u4e8e\u521b\u5efa\u5bf9\u8c61\u7684\u57fa\u672c\u6784\u9020\u5355\u5143<\/strong>\uff0c\u5b83\u5b9a\u4e49\u4e86\u5bf9\u8c61\u7684\u5c5e\u6027\u548c\u884c\u4e3a\uff0c\u5e76\u63d0\u4f9b\u4e86\u4e00\u79cd\u91cd\u7528\u4ee3\u7801\u7684\u673a\u5236\u3002<\/p>\n<p><em>\u8ba9\u6211\u4eec\u4ee5\u94f6\u884c\u8d26\u6237\u4e3a\u4f8b\uff0c\u5b9a\u4e49\u4e00\u4e2a\u7b80\u5355\u7684Java\u7c7b\u6765\u8868\u793a\u94f6\u884c\u8d26\u6237\uff1a<\/em><\/p>\n<pre><code class=\"prettyprint\"  class=\"language-java\">public class BankAccount {\n    \/\/ \u5c5e\u6027\n    private String ownerName;\n    private String accountNumber;\n    private double balance;\n\n    \/\/ \u65b9\u6cd5\n    public void deposit(double amount) {\n        balance += amount;\n    }\n\n    public void withdraw(double amount) {\n        if (amount &lt;= balance) {\n            balance -= amount;\n        } else {\n            System.out.println(&quot;\u4f59\u989d\u4e0d\u8db3\uff01&quot;);\n        }\n    }\n\n    public double getBalance() {\n        return balance;\n    }\n}<\/code><\/pre>\n<p><em>\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2a<code class=\"prettyprint\" >BankAccount<\/code>\u7c7b\uff0c\u5b83\u6709\u4e09\u4e2a\u5c5e\u6027\uff08<code class=\"prettyprint\" >ownerName<\/code>\u3001<code class=\"prettyprint\" >accountNumber<\/code>\u3001<code class=\"prettyprint\" >balance<\/code>\uff09\u548c\u4e09\u4e2a\u65b9\u6cd5\uff08<code class=\"prettyprint\" >deposit<\/code>\u3001<code class=\"prettyprint\" >withdraw<\/code>\u3001<code class=\"prettyprint\" >getBalance<\/code>\uff09\u3002\u8fd9\u4e2a\u7c7b\u63cf\u8ff0\u4e86\u94f6\u884c\u8d26\u6237\u7684\u7ed3\u6784\u548c\u64cd\u4f5c\u3002<\/em><\/p>\n<h2 id=\"toc-3\">\u521b\u5efa\u5bf9\u8c61<\/h2>\n<p>\u4e00\u65e6\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2a\u7c7b\uff0c\u5c31\u53ef\u4ee5\u521b\u5efa\u8be5\u7c7b\u7684\u5bf9\u8c61\u3002\u5728Java\u4e2d\uff0c\u901a\u8fc7\u4f7f\u7528\u5173\u952e\u5b57<code class=\"prettyprint\" >new<\/code>\u6765\u521b\u5efa\u5bf9\u8c61\u3002<\/p>\n<p><em>\u4f8b\u5982\uff0c\u8981\u521b\u5efa\u4e00\u4e2a<code class=\"prettyprint\" >BankAccount<\/code>\u5bf9\u8c61\uff0c\u53ef\u4ee5\u8fd9\u6837\u505a\uff1a<\/em><\/p>\n<pre><code class=\"prettyprint\"  class=\"language-java\">BankAccount myAccount = new BankAccount();<\/code><\/pre>\n<p><em>\u8fd9\u884c\u4ee3\u7801\u521b\u5efa\u4e86\u4e00\u4e2a\u540d\u4e3a<code class=\"prettyprint\" >myAccount<\/code>\u7684<code class=\"prettyprint\" >BankAccount<\/code>\u5bf9\u8c61\u3002\u73b0\u5728\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u8fd9\u4e2a\u5bf9\u8c61\u6765\u5b58\u6b3e\u3001\u53d6\u6b3e\u6216\u67e5\u8be2\u4f59\u989d\u3002<\/em><\/p>\n<h2 id=\"toc-4\">\u5c5e\u6027\u548c\u65b9\u6cd5<\/h2>\n<p>\u5728\u4e00\u4e2a\u7c7b\u4e2d\uff0c\u5c5e\u6027\u7528\u4e8e\u8868\u793a\u5bf9\u8c61\u7684\u72b6\u6001\uff0c\u65b9\u6cd5\u7528\u4e8e\u8868\u793a\u5bf9\u8c61\u7684\u884c\u4e3a\u3002\u5c5e\u6027\u901a\u5e38\u662f\u5bf9\u8c61\u7684\u7279\u5f81\u6216\u6570\u636e\uff0c\u800c\u65b9\u6cd5\u5219\u662f\u5bf9\u8c61\u7684\u64cd\u4f5c\u6216\u884c\u4e3a\u3002<\/p>\n<h3 id=\"toc-5\">\u5c5e\u6027<\/h3>\n<p><em>\u5728\u4e0a\u9762\u7684<code class=\"prettyprint\" >BankAccount<\/code>\u7c7b\u4e2d\uff0c<code class=\"prettyprint\" >ownerName<\/code>\u3001<code class=\"prettyprint\" >accountNumber<\/code>\u548c<code class=\"prettyprint\" >balance<\/code>\u662f\u5c5e\u6027\uff0c\u5b83\u4eec\u7528\u4e8e\u63cf\u8ff0\u94f6\u884c\u8d26\u6237\u7684\u72b6\u6001\u3002\u5c5e\u6027\u901a\u5e38\u5e94\u8be5\u662f\u79c1\u6709\u7684\uff0c\u4ee5\u5c01\u88c5\u5bf9\u8c61\u7684\u5185\u90e8\u72b6\u6001\uff0c\u53ea\u80fd\u901a\u8fc7\u65b9\u6cd5\u6765\u8bbf\u95ee\u548c\u4fee\u6539\u3002<\/em><\/p>\n<h3 id=\"toc-6\">\u65b9\u6cd5<\/h3>\n<p><em>\u65b9\u6cd5\u5b9a\u4e49\u4e86\u5bf9\u8c61\u7684\u884c\u4e3a\u3002\u5728<code class=\"prettyprint\" >BankAccount<\/code>\u7c7b\u4e2d\uff0c<code class=\"prettyprint\" >deposit<\/code>\u3001<code class=\"prettyprint\" >withdraw<\/code>\u548c<code class=\"prettyprint\" >getBalance<\/code>\u662f\u65b9\u6cd5\uff0c\u5b83\u4eec\u7528\u4e8e\u6267\u884c\u5b58\u6b3e\u3001\u53d6\u6b3e\u548c\u67e5\u8be2\u4f59\u989d\u7684\u64cd\u4f5c\u3002\u65b9\u6cd5\u662f\u5bf9\u8c61\u7684\u884c\u4e3a\u548c\u529f\u80fd\u7684\u5b9e\u73b0\u3002<\/em><\/p>\n<h2 id=\"toc-7\">\u5c01\u88c5<\/h2>\n<p>\u5c01\u88c5\u662f\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\u7684\u4e00\u4e2a\u91cd\u8981\u539f\u5219\uff0c\u5b83\u6307\u7684\u662f\u5c06<strong>\u5bf9\u8c61\u7684\u5185\u90e8\u72b6\u6001\uff08\u5c5e\u6027\uff09\u9690\u85cf\u8d77\u6765\uff0c\u5e76\u901a\u8fc7\u516c\u5171\u65b9\u6cd5\u6765\u8bbf\u95ee\u548c\u4fee\u6539\u8fd9\u4e9b\u72b6\u6001<\/strong>\u3002<\/p>\n<p>\u5728<code class=\"prettyprint\" >BankAccount<\/code>\u7c7b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528\u4e86\u5c01\u88c5\uff0c\u5c06\u5c5e\u6027<code class=\"prettyprint\" >ownerName<\/code>\u3001<code class=\"prettyprint\" >accountNumber<\/code>\u548c<code class=\"prettyprint\" >balance<\/code>\u58f0\u660e\u4e3a\u79c1\u6709\u5c5e\u6027\uff0c\u5e76\u63d0\u4f9b\u4e86\u516c\u5171\u65b9\u6cd5\uff08<code class=\"prettyprint\" >deposit<\/code>\u3001<code class=\"prettyprint\" >withdraw<\/code>\u3001<code class=\"prettyprint\" >getBalance<\/code>\uff09\u6765\u8bbf\u95ee\u548c\u4fee\u6539\u8fd9\u4e9b\u5c5e\u6027\u3002\u8fd9\u6837\uff0c\u5916\u90e8\u4ee3\u7801\u4e0d\u80fd\u76f4\u63a5\u8bbf\u95ee\u548c\u4fee\u6539\u5bf9\u8c61\u7684\u5c5e\u6027\uff0c\u5fc5\u987b\u901a\u8fc7\u65b9\u6cd5\u6765\u64cd\u4f5c\u3002<\/p>\n<h2 id=\"toc-8\">\u7ee7\u627f<\/h2>\n<p>\u7ee7\u627f\u662f\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\u4e2d\u7684\u53e6\u4e00\u4e2a\u5173\u952e\u6982\u5ff5\u3002\u5b83\u5141\u8bb8\u4f60\u521b\u5efa\u4e00\u4e2a\u65b0\u7c7b\uff0c\u8be5\u7c7b\u53ef\u4ee5\u7ee7\u627f\u53e6\u4e00\u4e2a\u7c7b\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\u3002\u7ee7\u627f\u4f7f\u5f97\u4ee3\u7801\u91cd\u7528\u66f4\u5bb9\u6613\uff0c\u5e76\u5141\u8bb8\u4f60\u521b\u5efa\u4e00\u4e2a\u7c7b\u5c42\u6b21\u7ed3\u6784\uff0c\u5176\u4e2d\u4e00\u4e2a\u7c7b\uff08\u5b50\u7c7b\uff09\u7ee7\u627f\u53e6\u4e00\u4e2a\u7c7b\uff08\u7236\u7c7b\uff09\u7684\u7279\u5f81\u548c\u884c\u4e3a\u3002<\/p>\n<p><em>\u8ba9\u6211\u4eec\u4ee5\u4e00\u4e2a\u793a\u4f8b\u6765\u7406\u89e3\u7ee7\u627f\u3002\u5047\u8bbe\u6211\u4eec\u8981\u521b\u5efa\u4e00\u4e2a\u66f4\u590d\u6742\u7684\u94f6\u884c\u8d26\u6237\u7cfb\u7edf\uff0c\u5176\u4e2d\u6709\u591a\u79cd\u7c7b\u578b\u7684\u8d26\u6237\uff0c\u5982\u50a8\u84c4\u8d26\u6237\u548c\u652f\u7968\u8d26\u6237\u3002\u8fd9\u4e9b\u4e0d\u540c\u7c7b\u578b\u7684\u8d26\u6237\u6709\u4e00\u4e9b\u5171\u540c\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\uff0c\u5982\u8d26\u6237\u6301\u6709\u8005\u7684\u59d3\u540d\u548c\u8d26\u6237\u53f7\u7801\uff0c\u4f46\u4e5f\u6709\u4e00\u4e9b\u7279\u5b9a\u4e8e\u6bcf\u79cd\u7c7b\u578b\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\u3002<\/em><\/p>\n<pre><code class=\"prettyprint\"  class=\"language-java\">public class BankAccount {\n    \/\/ \u5171\u540c\u7684\u5c5e\u6027\n    private String ownerName;\n    private String accountNumber;\n    private double balance;\n\n    \/\/ \u5171\u540c\u7684\u65b9\u6cd5\n    public void deposit(double amount) {\n        balance += amount;\n    }\n\n    public void withdraw(double amount) {\n        if (amount &lt;= balance) {\n            balance -= amount;\n        } else {\n            System.out.println(&quot;\u4f59\u989d\u4e0d\u8db3\uff01&quot;);\n        }\n    }\n\n    public double getBalance() {\n        return balance\n    }\n}<\/code><\/pre>\n<p><em>\u73b0\u5728\uff0c\u6211\u4eec\u53ef\u4ee5\u521b\u5efa\u5177\u4f53\u7684\u8d26\u6237\u7c7b\u578b\uff0c\u5982\u50a8\u84c4\u8d26\u6237\u548c\u652f\u7968\u8d26\u6237\uff0c\u5b83\u4eec\u7ee7\u627f\u81ea<code class=\"prettyprint\" >BankAccount<\/code>\u7236\u7c7b\uff0c\u5e76\u53ef\u4ee5\u6dfb\u52a0\u7279\u5b9a\u4e8e\u6bcf\u79cd\u7c7b\u578b\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\uff1a<\/em><\/p>\n<pre><code class=\"prettyprint\"  class=\"language-java\">public class SavingsAccount extends BankAccount {\n    private double interestRate;\n\n    public SavingsAccount(String ownerName, String accountNumber, double initialBalance, double interestRate) {\n        \/\/ \u8c03\u7528\u7236\u7c7b\u6784\u9020\u65b9\u6cd5\u521d\u59cb\u5316\u5171\u540c\u5c5e\u6027\n        super(ownerName, accountNumber, initialBalance);\n        this.interestRate = interestRate;\n    }\n\n    public void applyInterest() {\n        double interest = getBalance() * interestRate;\n        deposit(interest);\n    }\n}\n\npublic class CheckingAccount extends BankAccount {\n    private double overdraftLimit;\n\n    public CheckingAccount(String ownerName, String accountNumber, double initialBalance, double overdraftLimit) {\n        \/\/ \u8c03\u7528\u7236\u7c7b\u6784\u9020\u65b9\u6cd5\u521d\u59cb\u5316\u5171\u540c\u5c5e\u6027\n        super(ownerName, accountNumber, initialBalance);\n        this.overdraftLimit = overdraftLimit;\n    }\n\n    public void withdrawWithOverdraft(double amount) {\n        if (amount &lt;= getBalance() + overdraftLimit) {\n            withdraw(amount);\n        } else {\n            System.out.println(&quot;\u8d85\u51fa\u900f\u652f\u989d\u5ea6\uff01&quot;);\n        }\n    }\n}<\/code><\/pre>\n<p><em>\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c<code class=\"prettyprint\" >SavingsAccount<\/code>\u548c<code class=\"prettyprint\" >CheckingAccount<\/code>\u7c7b\u90fd\u7ee7\u627f\u81ea<code class=\"prettyprint\" >BankAccount<\/code>\u7236\u7c7b\uff0c\u5e76\u6dfb\u52a0\u4e86\u7279\u5b9a\u4e8e\u6bcf\u79cd\u7c7b\u578b\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\u3002\u8fd9\u6837\uff0c\u6211\u4eec\u53ef\u4ee5\u521b\u5efa\u4e0d\u540c\u7c7b\u578b\u7684\u8d26\u6237\u5bf9\u8c61\uff0c\u6bcf\u79cd\u7c7b\u578b\u90fd\u7ee7\u627f\u4e86\u5171\u540c\u7684\u5c5e\u6027\u548c\u65b9\u6cd5\uff0c\u5e76\u4e14\u5177\u6709\u81ea\u5df1\u7684\u7279\u6027\u3002<\/em><\/p>\n<h2 id=\"toc-9\">\u591a\u6001<\/h2>\n<p>\u5b83\u5141\u8bb8\u4e0d\u540c\u7c7b\u578b\u7684\u5bf9\u8c61\u5bf9\u76f8\u540c\u7684\u6d88\u606f\uff08\u65b9\u6cd5\u8c03\u7528\uff09\u505a\u51fa\u4e0d\u540c\u7684\u54cd\u5e94\u3002\u591a\u6001\u4f7f\u5f97\u4ee3\u7801\u66f4\u7075\u6d3b\u548c\u53ef\u6269\u5c55\uff0c\u80fd\u591f\u5904\u7406\u4e0d\u540c\u7c7b\u578b\u7684\u5bf9\u8c61\uff0c\u800c\u65e0\u9700\u77e5\u9053\u5176\u5177\u4f53\u7c7b\u578b\u3002<\/p>\n<p><em>\u8ba9\u6211\u4eec\u4ee5\u4e00\u4e2a\u591a\u6001\u7684\u793a\u4f8b\u6765\u7406\u89e3\u3002\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a<code class=\"prettyprint\" >printAccountInfo<\/code>\u65b9\u6cd5\uff0c\u8be5\u65b9\u6cd5\u63a5\u53d7\u4e00\u4e2a\u94f6\u884c\u8d26\u6237\u5bf9\u8c61\uff0c\u5e76\u6253\u5370\u8d26\u6237\u4fe1\u606f\uff1a<\/em><\/p>\n<pre><code class=\"prettyprint\"  class=\"language-java\">public void printAccountInfo(BankAccount account) {\n    System.out.println(&quot;\u8d26\u6237\u4fe1\u606f\uff1a&quot;);\n    System.out.println(&quot;\u8d26\u6237\u6301\u6709\u8005\uff1a&quot; + account.getOwnerName());\n    System.out.println(&quot;\u8d26\u6237\u53f7\u7801\uff1a&quot; + account.getAccountNumber());\n    System.out.println(&quot;\u5f53\u524d\u4f59\u989d\uff1a&quot; + account.getBalance());\n}<\/code><\/pre>\n<p><em>\u8fd9\u4e2a\u65b9\u6cd5\u63a5\u53d7\u4e00\u4e2a<code class=\"prettyprint\" >BankAccount<\/code>\u5bf9\u8c61\u4f5c\u4e3a\u53c2\u6570\uff0c\u4f46\u5b9e\u9645\u4e0a\u53ef\u4ee5\u4f20\u9012\u4efb\u4f55\u7ee7\u627f\u81ea<code class=\"prettyprint\" >BankAccount<\/code>\u7684\u5bf9\u8c61\uff0c\u5982\u50a8\u84c4\u8d26\u6237\u6216\u652f\u7968\u8d26\u6237\u3002\u8fd9\u662f\u591a\u6001\u7684\u4f53\u73b0\uff0c\u540c\u4e00\u4e2a\u65b9\u6cd5\u53ef\u4ee5\u9002\u7528\u4e8e\u4e0d\u540c\u7c7b\u578b\u7684\u5bf9\u8c61\u3002<\/em><\/p>\n<pre><code class=\"prettyprint\"  class=\"language-java\">SavingsAccount savingsAccount = new SavingsAccount(&quot;Alice&quot;, &quot;SA123&quot;, 1000.0, 0.03);\nCheckingAccount checkingAccount = new CheckingAccount(&quot;Bob&quot;, &quot;CA456&quot;, 500.0, 100.0);\n\nprintAccountInfo(savingsAccount); \/\/ \u6253\u5370\u50a8\u84c4\u8d26\u6237\u4fe1\u606f\nprintAccountInfo(checkingAccount); \/\/ \u6253\u5370\u652f\u7968\u8d26\u6237\u4fe1\u606f\n<\/code><\/pre>\n<p><em>\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u5206\u522b\u4f20\u9012\u4e86\u50a8\u84c4\u8d26\u6237\u548c\u652f\u7968\u8d26\u6237\u5bf9\u8c61\u7ed9<code class=\"prettyprint\" >printAccountInfo<\/code>\u65b9\u6cd5\uff0c\u5b83\u80fd\u591f\u6b63\u786e\u5730\u6253\u5370\u4e0d\u540c\u7c7b\u578b\u8d26\u6237\u7684\u4fe1\u606f\u3002<\/em><\/p>\n<p>\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\u662fJava\u7f16\u7a0b\u7684\u6838\u5fc3\uff0c\u5b83\u63d0\u4f9b\u4e86\u4e00\u79cd\u7ec4\u7ec7\u548c\u7ba1\u7406\u4ee3\u7801\u7684\u5f3a\u5927\u65b9\u5f0f\uff0c\u4f7f\u5f97\u4ee3\u7801\u66f4\u5177\u53ef\u8bfb\u6027\u3001\u53ef\u7ef4\u62a4\u6027\u548c\u53ef\u6269\u5c55\u6027\u3002\u5728\u672c\u7bc7\u535a\u5ba2\u4e2d\uff0c\u6211\u4eec\u8ba8\u8bba\u4e86\u5bf9\u8c61\u3001\u7c7b\u3001\u5c01\u88c5\u3001\u7ee7\u627f\u3001\u591a\u6001\u7b49\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\u7684\u6838\u5fc3\u6982\u5ff5\u3002\u901a\u8fc7\u6df1\u5165\u7406\u89e3\u8fd9\u4e9b\u6982\u5ff5\uff0c\u5e76\u5728\u5b9e\u9645\u7f16\u7a0b\u4e2d\u5e94\u7528\u5b83\u4eec\uff0c\u4f60\u5c06\u80fd\u591f\u66f4\u597d\u5730\u8bbe\u8ba1\u548c\u7ec4\u7ec7Java\u7a0b\u5e8f\uff0c\u5145\u5206\u53d1\u6325\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\u7684\u4f18\u52bf\u3002<\/p>\n<p>\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014<br \/>\n\u7248\u6743\u58f0\u660e\uff1a\u672c\u6587\u4e3aCSDN\u535a\u4e3b\u300c\u7e41\u4f9dFanyi\u300d\u7684\u539f\u521b\u6587\u7ae0\uff0c\u9075\u5faaCC 4.0 BY-SA\u7248\u6743\u534f\u8bae\uff0c\u8f6c\u8f7d\u8bf7\u9644\u4e0a\u539f\u6587\u51fa\u5904\u94fe\u63a5\u53ca\u672c\u58f0\u660e\u3002<br \/>\n\u539f\u6587\u94fe\u63a5\uff1a<a href=\"https:\/\/blog.csdn.net\/qq_21484461\/article\/details\/132645327\">https:\/\/blog.csdn.net\/qq_21484461\/article\/details\/132645327<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\u7684\u827a\u672f \u9762\u5411\u5bf9\u8c61\u7f16\u7a0b\uff08Object-Oriented Programming\uff0cOOP\uff09\u662fJAVA\u4e2d [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":217,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,5],"tags":[],"_links":{"self":[{"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/posts\/215"}],"collection":[{"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=215"}],"version-history":[{"count":2,"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/posts\/215\/revisions"}],"predecessor-version":[{"id":218,"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/posts\/215\/revisions\/218"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/media\/217"}],"wp:attachment":[{"href":"http:\/\/ericw.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=215"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=215"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=215"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}