In Java, all classes are loaded dynamically in the JVM the first time you use a class.
Does this mean that if I have a class in the source file and I do not reference it, then its object is Class
not created (i.e. the .class
file is not created)?
In the code sample below, iam does not reference the test3
class, but its class object is still created.
class test1 {
static {
System.out.println("static block of test1");
}
}
class test2{
static {
System.out.println("static block of test2");
}
}
class test3 {}
class MyExample1 {
public static void main(String ...strings ) {
new test1();
new test2();
}
}
Why is the test3.class
file created ?
source
share