public class SuperTest03 {
public static void main(String[] args) {
CreditAccount ca1 = new CreditAccount();
System.out.println(ca1.getActno() + "," + ca1.getBanlance() + "," + ca1.getCredit());
CreditAccount ca2 = new CreditAccount("1111",10000.0,0.09);
System.out.println(ca2.getActno() + "," + ca2.getBanlance() + "," + ca2.getCredit());
}
}
class Account{
private String actno;
private double banlance;
public Account() {
}
public Account(String actno,double banlance) {
this.actno = actno;
this.banlance = banlance;
}
public void setActno(String actno) {
this.actno = actno;
}
public String getActno() {
return actno;
}
public void setBanlance(double banlance) {
this.banlance = banlance;
}
public double getBanlance() {
return banlance;
}
}
class CreditAccount extends Account{
private double credit;
public CreditAccount() {
}
public CreditAccount(String actno,double banlance,double credit) {
//私有的属性只能在本类中访问。
/*
this.actno = actno;
this.banlance = banlance;
*/
//调用父类中有参数的构造函数
super(actno,banlance);
this.credit = credit;
}
public void setCredit(double credit) {
this.credit = credit;
}
public double getCredit() {
return credit;
}
}
super(实参)的用法
最新推荐文章于 2025-12-02 17:50:12 发布
该博客展示了Java编程中的类继承概念,通过`CreditAccount`类继承`Account`类来实现账户功能的扩展。在`CreditAccount`类中,定义了信用额度属性并提供了相关方法。博客还演示了如何使用构造器初始化对象,包括无参构造器和带参构造器的使用,以及如何调用父类的构造器。示例代码包括创建和打印两个不同类型的账户实例。
201

被折叠的 条评论
为什么被折叠?



