码迷,mamicode.com
首页 > 其他好文 > 详细

super关键字学习-2-super(实参)的用法

时间:2021-01-21 10:52:51      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:keyword   int   test   关键字   count   and   new   super关键字   学习   

package superkeyword;
/*
*   举个例子:在恰当的时间使用:super(实际参数列表);
* */

//测试程序
public class SuperTest03 {
    public static void main(String[] args) {
        CreditAccount ca1 = new CreditAccount();
        System.out.println(ca1.getActno() + "," + ca1.getBalance() + "," + ca1.getCredit());
        CreditAccount ca2 = new CreditAccount("1111",10000.0,0.999);
        System.out.println(ca2.getActno() + "," + ca2.getBalance() + "," + ca2.getCredit());

    }
}

//账户
class Account{
    //属性
    private String actno;
    private double balance;

    //构造方法
    public Account(){

    }
    public Account(String actno,double balance){
        this.actno = actno;
        this.balance = balance;
    }

    //setter and getter

    public String getActno() {
        return actno;
    }

    public void setActno(String actno) {
        this.actno = actno;
    }

    public double getBalance() {
        return balance;
    }

    public void setBalance(double balance) {
        this.balance = balance;
    }
}

//信用账户
class CreditAccount extends Account{

    //属性:信誉度(诚信值)
    //子类特有的一个特征,父类没有
    private double credit;

    //构造方法
    //分析一下程序是否存在编译错误?????
    public CreditAccount(String actno,double balance,double credit){
        //私有的属性,只能在本类中访问。
        /*this.actno = actno;
        this.balance = credit;*/
        super(actno,balance);
        this.credit = credit;
    }
    public CreditAccount(){

    }

    //setter and getter方法

    public double getCredit() {
        return credit;
    }

    public void setCredit(double credit) {
        this.credit = credit;
    }
}















super关键字学习-2-super(实参)的用法

标签:keyword   int   test   关键字   count   and   new   super关键字   学习   

原文地址:https://www.cnblogs.com/DcWzc/p/14305214.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!