package zdbExtends;
public class Grandparent {
public Grandparent(){
System.out.println("Grandparent create.");
}
public Grandparent(String string){
System.out.println("Grandparent create.string");
}
}
package zdbExtends;
public class Parent extends Grandparent {
public Parent(){
System.out.println("Parent Create.");
}
public Parent(String string){
System.out.println("Parent Create.string");
}
}
package zdbExtends;
public class Parent extends Grandparent {
public Parent(){
System.out.println("Parent Create.");
}
public Parent(String string){
System.out.println("Parent Create.string");
}
}
package zdbExtends;
public class Parent extends Grandparent {
public Parent(){
System.out.println("Parent Create.");
}
public Parent(String string){
System.out.println("Parent Create.string");
}
}
(二)总结:
继承:
1.子类继承父类,默认情况下调用无参构造函数,如果当父类中只用有参构造函数时,则子类发生错误;
2.调用父类中的有参构造函数使用super("");并且要放在第一行;
3.不允许继承的类:
final class 类名{
}
3.1以final声明的方法不允许覆盖。
3.2以final声明的变量不允许更改。