java父类和子类初始化顺序的深入理解
时间:2022-09-02 08:52:19|栏目:JAVA代码|点击: 次
继承类的构建过程是向外扩散的,子类初始化了,父类一定也初始化了
class Art{
Art(){
System.out.println("Art");
}
}
class Drawing extends Art{
Drawing(){
System.out.println("Drawing");
}
}
public class Cartoon extends Drawing {
Cartoon(){
System.out.println("Cartoon");
}
public static void main(String[] args) {
Art cartoon = new Cartoon();
}
}
输出为:
Art
Drawing
Cartoon
复制代码 代码如下:
class Art{
Art(){
System.out.println("Art");
}
}
class Drawing extends Art{
Drawing(){
System.out.println("Drawing");
}
}
public class Cartoon extends Drawing {
Cartoon(){
System.out.println("Cartoon");
}
public static void main(String[] args) {
Art cartoon = new Cartoon();
}
}
输出为:
复制代码 代码如下:
Art
Drawing
Cartoon
上一篇:springboot配置logback日志管理过程详解
栏 目:JAVA代码
本文标题:java父类和子类初始化顺序的深入理解
本文地址:http://www.codeinn.net/misctech/212545.html