- 最後登錄
- 2024-4-30
- 在線時間
- 0 小時
- 註冊時間
- 2017-12-25
- 閱讀權限
- 20
- 精華
- 0
- UID
- 17787565
- 帖子
- 172
- 積分
- 186 點
- 潛水值
- 6290 米
| 所有積分大於負-100的壞孩子,將可獲得重新機會成為懲罰生,權限跟幼兒生一樣。 看起來就是定義三個 class,Deposit 跟 SavingAccount 都要繼承 General,而且這三個 class 都要有三個 constructor,最直接的寫法可以是這樣- class General {
- String name;
- String address;
- General() {
- this(null);
- }
- General(String name) {
- this(name, null);
- }
- General(String name, String address) {
- this.name = name;
- this.address = address;
- }
- public void getDetails() {
- // do nothing
- }
- public void setDetails() {
- // do nothing
- }
- }
- class SavingAccount extends General {
- int accountNo;
- int balance;
- SavingAccount() {
- this(0);
- }
- SavingAccount(int no) {
- this(0, 0);
- }
- SavingAccount(int no, int balance) {
- this.accountNo = no;
- this.balance = balance;
- }
- public int getAccount() {
- return 0;
- }
- public void setAccount() {
- // do nothing
- }
- public void searchAccount() {
- // do nothing
- }
- }
- class Deposit extends General {
- int receiptNo;
- String date;
- int amount;
- Deposit() {
- this(0);
- }
- Deposit(int no) {
- this(0, 0);
- }
- Deposit(int no, int amount) {
- this.receiptNo = no;
- this.amount = amount;
- }
- public void setDeposit() {
- // do nothing
- }
- public void printDeposit() {
- // do nothing
- }
- }
複製代碼 ... |
|