packagecom.reflection;publicclassTest05{publicstaticvoidmain(String[] args){A a =newA();System.out.println(A.m);}}classA{staticint m =100;static{System.out.println("A类静态代码块初始化");
m =300;}// static int m = 100;publicA(){System.out.println();}}
注解与反射10:分析类初始化
packagecom.reflection;publicclassTest06{static{System.out.println("main类被加载");}publicstaticvoidmain(String[] args)throwsClassNotFoundException{// 主动引用// Son son = new Son();// 反射也会产生主动引用// Class.forName("com.reflection.Son");// 不会产生类的引用的方法System.out.println(Son.b);Son[] array =newSon[5];System.out.println(Son.M);}}classFather{staticint b =2;static{System.out.println("父类被加载");}}classSonextendsFather{static{System.out.println("子类被加载");
m =300;}staticint m =100;staticfinalintM=1;}
注解与反射09:类加载内存分析package com.reflection;public class Test05 { public static void main(String[] args) { A a = new A(); System.out.println(A.m); }}class A{ static int m = 100; static { System.out.println("A类静态代码块初始化