// 使用继承
public class Test2{
public static void main(String[] args){
Account act = new Account();
act.setActno("0715");
act.setBalance(2000);
System.out.println(act.getActno() + ",余额" + act.getBalance());
CreditAccount ca = new CreditAccount();
ca.setActno("0714");
ca.setBalance(1000);
ca.setCredit(1.02);
System.out.println(ca.getActno() + ",余额" + ca.getBalance() + ",信誉度" + ca.getCredit());
}
}
class Account{ //父类
private String actno;
private double balance;
public Account(){
}
public Account(String actno,double balance){
this.actno = actno;
this.balance = balance;
}
public void setActno(String actno){
this.actno = actno;
}
public String getActno(){
return actno;
}
public void setBalance(double balance){
this.balance = balance;
}
public double getBalance(){
return balance;
}
}
// 其他类型的账户:信用卡账户
// 账号、余额、信誉度
class CreditAccount extents Account //子类
{
private double credit;
public void setCredit(double credit){
this.credit = credit;
}
public double getCredit(){
return credit;
}
}