super(实参)的用法

该博客展示了Java编程中的类继承概念,通过`CreditAccount`类继承`Account`类来实现账户功能的扩展。在`CreditAccount`类中,定义了信用额度属性并提供了相关方法。博客还演示了如何使用构造器初始化对象,包括无参构造器和带参构造器的使用,以及如何调用父类的构造器。示例代码包括创建和打印两个不同类型的账户实例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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;
	}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值