可以,super是访问父类构造方法
例如:
public class Akk {
public static void main(String[] args) {
App p = new App("小红",19);
System.out.println("我的名字是:" + p.getName() + " , 我今年:" + p.getAge() + "了");
}
}
class Add {
private String name;
public Add(){}
public Add(String name){
this.name = name;
}
public void setName(String name){
this.name = name;
}
public String getName(){
return name;
}
}
class App extends Add {
private int age;
public App(){}
public App (String name,int age){
super(name);
this.age = age;
}
public void setAge(int age){
this.age = age;
}
public int getAge(){
return age;
}
} |