Detailed explanation of super keyword 2

package test7;
//Super keyword detailed 2
/*
 * The super keyword is used in the constructor:
 * Syntax: super(actual parameter)
 * Function: Call the constructor of the parent class through the constructor of the subclass
 * 
 * Syntax rules : If there is no this(``) in the first line of a constructor, and there is no display to call super()
 * The system will call super() by default
 * 
 * The call of super can only be placed in the first line of the constructor
 * super It cannot coexist with this
 * 
 * The constructor of the parent class is called through the constructor of the subclass. The function is to assign the supertype feature in the current subclass object.
 Although the super object is executed, it will not create the parent class object
 * When the constructor is executed, it may not be possible to create an object. Even if the constructor is executed, super does not create an object
 .* 
 * Disadvantages of the constructor:
 * Subclasses cannot create objects, types cannot be inherited, and the type of the singleton pattern has no subclasses
 * super. Access the supertype feature through the current subclass object, super() is to call the superclass constructor in the subclass constructor, the purpose is to assign the supertype feature in the subclass
 */


public class test7 {


public static void main(String[] args) {
debitAccount da=new debitAccount();
}


}
 
class Account{
private String actno;
private double balance; public Account(){ System.out.println("Account的无参数构造方法已被执行"); } public Account(String actno,double balance) { this.actno=actno; this.balance=balance; } //set and get public void getactno(String actno) { this.actno=actno; } public String getactno() { return actno; } public void getbalance(double balance) { this.balance=balance; } public double getbalance() {
























return balance;
}
}


class debitAccount extends Account{
private double debit;  public debitAccount() { //If there is no constructor, there is super.() by default } public void getdebit(double debit) { this.debit=debit; } public double getdebit() { return debit; } }
















Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325891545&siteId=291194637