欢迎光临散文网 会员登陆 & 注册

150天打卡day18_多态的意义

2021-05-13 18:48 作者:关阿姨的Java日记  | 我要投稿

实现多态的三个必要条件

  • 继承

  • 重写

  • 向上造型

public class ABCImpl implements ABC {   private double balance; // 卡内余额,允许最多透支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("支付电话费成功");       return true;         }


 

 


测试


150天打卡day18_多态的意义的评论 (共 条)

分享到微博请遵守国家法律