- class A {
-
- static{
- System.out.println("A静态块,加载A类时运行");
- }
-
- public A() {
- super();
- System.out.println("A类对象构造完成,当前对象地址:"+this);
- }
- {
- System.out.println("A代码块,对象构造初始化");
- }
- }
- class B extends A{
- static{
- System.out.println("B静态块,加载B类时运行");
- }
- public B() {
- super();
- System.out.println("B类对象构造完成,当前对象地址:"+this);
- }
- {
- System.out.println("B代码块,对象构造初始化");
- }
- }
- public class C extends B{
- static{
- System.out.println("C静态块,加载C类时运行");
- }
- public C() {
- super();
- System.out.println("C类对象构造完成,当前对象地址:"+this);
- }
- {
- System.out.println("C代码块,对象构造初始化");
- }
- public static void main(String[] args) {
- new C();
- }
- }
复制代码
运行结果:(回复可见)
|
|