前提知识:
(暂未发布)面向对象继承相关知识
(暂未发布)static与静态代码块
(暂未发布)JVM加载类的顺序
public class ParentMainTest { static int x; static { x++; System.out.println("ParentMainTest_static..." + x); } public static void main(String[] args) { new SonMainTest(6); } int n = 10; { n++; System.out.println("ParentMainTest..." + n); } } public class SonMainTest extends ParentMainTest{ SonMainTest(int a){ this.a=a; System.out.println("SonMainTest.a=" + a ); } int a; { System.out.println("SonMainTest..."+this.a); } static { x++; System.out.println("SonMainTest_static..." +x); } }
输出结果: ParentMainTest_static...1 SonMainTest_static...2 ParentMainTest...11 SonMainTest...0 SonMainTest.a=6
答案解析
具体分析:等我有时间再酌情分析
原文地址:https://www.cnblogs.com/qq1452753919/p/10556081.html
时间: 2024-10-10 08:01:08