150天打卡day18_多態(tài)的意義
實(shí)現(xiàn)多態(tài)的三個必要條件
繼承
重寫
向上造型
public class ABCImpl implements ABC {? ?private double balance; // 卡內(nèi)余額,允許最多透支2000? ?private String password; // 賬號密碼? ?public ABCImpl() {}? ?public ABCImpl(double balance, String password) {? ? ? super();? ? ? this.balance = balance;? ? ? this.password = password; }? //返回賬戶余額? ?public double getBalance() {? ? ? return balance; }? ?//取錢? ?public boolean getMoney(double number) {? ? ? if ((balance - number) >= -2000) {? ? ? ?balance -= number;? ? ? }? ? ? return false; } @Override? ?public boolean checkPwd(String input) {? ? ? if (password.equals(input)) {? ? ? ?return true;? ? ? }? ? ? return false;? ? ?} @Override? ?public boolean payTelBil(String phoneNum, double sum) {? ? ? ? ? ? ?System.out.println("支付電話費(fèi)成功");? ? ? ?return true;? ? ? ? ?}
?
?
測試