学习JVM原理-15.类initialization与继承关系

摘自《深入理解Java虚拟机》周志明著

class Bean {
	static {
		System.out.println("Bean inited");
	}

}

class SubBean extends Bean{
	static {
		System.out.println("SubBean inited");
	}
}


main(){
    int  i = SubBean.subBeanValue; 
/*会先打印"Bean inited",再打印"SubBean inited" */
/*JVM会保证在子类的<clinit>方法执行之前,父类的<clint>()方法已经执行完毕*/
}	
 	

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.