简单的关于类的继承(一)
package collection;
class Father{
public Father(String arg) {
System.out.println(arg);
}
}
class Son extends Father{
public Son(){
System.out.println("Son");
}
}
public class MyExtends {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Son son=new Son();
}
// 父类没有默认的构造函数,子类会编译通不过,所以就会报错
}
下面的代码 就不报错了
package collection;
class Father{
public Father(String arg) {
System.out.println(arg);
}
}
class Son extends Father{
public Son(String arg) {
super(arg);
System.out.println(arg);
}
}
public class MyExtends {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Son son=new Son("aa");
}
}
欢迎关注公众号:Java后端技术全栈