父类:
class father{
String name;
int age;
father(){}
father(String name,int age){
this.name=name;
this.age=age;
}
}
子类::
class Son{
String id;
son( String name,int age,String id){
super(name,age);
this.id=id;
}
}
主类:
class MainClass{
public static void main(String[]args){
Son son=new Son("wanglin",18,"10001");//子类在创建对象的时候就调用了父类的非空构造函数}
} |