2014.9.2
Why does the reference of the static method of the parent class through subclass not cause subclass initialization?
See the following program:
Class superclass
{
Static {
System. Out. println ("superclass init ");
}
Public static int values = 123;
Public static void supermethod ()
{
System. Out. println ("I am supermethod .");
}
}
Class subclass extends superclass
{
Static {
System. Out. println ("subclass Init ;");
}
}
Public class notinitial
{
Public static void main (string [])
{
System. Out. println (subclass. value );
Subclass. supermethod ();
}
}
First, the JVM loads the notinitial class,
Load,
Verify
Preparation
For the subclass. supermethod (); Statement, the byte code command is invokestatic,
Therefore, we need to resolve the subclass class first.
Load subclass,
This method is found in subclass. No
Load the subclass parent class, supperclass
Find in superclass.
Initialization,
Call the main method,
Execute invokestatic, followed by direct reference.
This article from the "thick and thin hair" blog, please be sure to keep this source http://duanzhenyue.blog.51cto.com/9360091/1550124
Why does the reference of the static method of the parent class through subclass not cause subclass initialization?