做个简单笔录,就当是重温下基础知识. 1.先看代码: package com.test; public class Test { public static void main(String[] args) { Son s = new Son(); } } class Parent{ int parent = 10; { System.out.println("parent中的初始化块"); } static{ System.out.println("parent中stati…
首先我们来看看引用类型的成员初始化过程 我们来看一个例子吧 class Program { static void Main(string[] args) { DriveB d = new DriveB(); } } class BaseA { static DisplayClass a = new DisplayClass("基类静态成员初始化"); DisplayClass BaseA_c = new DisplayClass(&qu…
结论:对于静态变量.静态初始化块.变量.初始化块.构造器,它们的初始化顺序依次是(静态变量.静态初始化块)>(变量.初始化块)>构造器. public class Test4 { @Test public void test(){ child child = new child(); } } class parent{ public static String parentStaticField = "父类静态变量"; public String parentNormalF…