package com.whut.zzh;
class ZZH {
static {
System.out.println("Class ZZH");
}
}
public class Test1 {
public static void main(String[] args) throws ClassNotFoundException {
//获得系统加载器
ClassLoader loader = ClassLoader.getSystemClassLoader();//非主动使用,不会导致类的初始化
Class<?> clazz = loader.loadClass("com.whut.zzh.ZZH");
System.out.println("---------------------");
clazz = Class.forName("com.whut.zzh.ZZH");
}
}
结果:
---------------------
Class ZZH