「Java」「abstract」 Chapter4 Question1

Given:
abstract class Account{
 abstract void deposit(double atm);
 public abstract boolean withdraw(double atm);
}

class SubAccount extends Account{
// @Override
// void deposit(double atm) {    
// }
//
// @Override
// public boolean withdraw(double atm) {
//  return false;
// }
}



What two changes, made independently,will enable the code to compile?
  1. Change the signature of Account to: public class Account.
  2. Change the signature of SubAccount to:public abstract class SubAccount.
  3. Implement private methods for deposit and withdraw in SubAccount.
  4. Implement public methods for deposit and withdraw in SubAccount.
  5. Change Signature of SubAccount to: SubAccount implements Account.
  6. Make Account an interface.
中文翻譯:

以下哪兩個選項能獨自變更並完成編譯?
  1. 更改Account簽章成: public class Account (錯誤,因Account裡有abstract方法)
  2. 更改SubAccount簽章成: public abstract class SubAccount(正確,因子類別SubAccount改成abstract,也就不需要覆寫方法)
  3. 實作 修飾子為private 的 deposit 與 withdraw 方法(錯誤,因Account最高為default,而private權限更高於default。子類別的覆寫方法權限不可高於父類別 )
  4. 實作 修飾子為public 的 deposit 與 withdraw 方法(正確,public權限高於覆類別 deposit 與 withdraw方法。)
  5. 更改SubAccount簽章成: SubAccount implements Account(錯誤,Account不是interface)
  6. 更改 Account 為 interface 介面。 (錯誤,且毫無異議)

留言

這個網誌中的熱門文章

[Excel]國曆轉農曆VBA

「生活」眉毛觀人

「CSS」「div區塊介紹」 三欄式網頁排版設計