标签:pre src 初始化 com 构造函数 静态属性 his extends public
public class Father { private String pro="1"; private static String staticPro="2"; { System.out.println("父普通代码块"); System.out.println(this.pro); System.out.println(this.staticPro); } static { System.out.println("父静态代码块"); } public Father() { System.out.println("父类构造"); System.out.println(this.pro); System.out.println(this.staticPro); } }
子类:
public class Son extends Father { private String pro="1"; private static String staticPro="2"; { System.out.println("子普通代码块"); System.out.println(this.pro); System.out.println(this.staticPro); } static { System.out.println("子静态代码块"); } public Son() { System.out.println("子类构造"); System.out.println(this.pro); System.out.println(this.staticPro); } }
测试:
public class test { public static void main(String[] args) { Son son = new Son(); } }
返回结果:
标签:pre src 初始化 com 构造函数 静态属性 his extends public
原文地址:https://www.cnblogs.com/Tractors/p/11198303.html