class fathera{
public fathera () {
System.out.println("父类中的无参构造方法:");
}
public void p() {
System.out.println("父类中的方法");
}
}
class childs extends fathera{
public childs () {
System.out.println("子类中的无参构造方法");}
public childs (int b) {
System.out.println("子类中的含参数构造方法");
}
public void p() {
System.out.println("子类中的方法");
}
}
public class Day04 {
public static void main(String[] args) {
// TODO Auto-generated method stub
childs a =new childs (1);
fathera b=new fathera();
}
}
运行:
父类中的无参构造方法:
子类中的含参数构造方法
父类中的无参构造方法: