In Java all classes are loaded into the JVM dynamically, upon the first use of a class.
Does it mean if i have class in a my source file and I do not make any reference to it then its Class object is not created (i.e. .class file is not created)?
In the sample code below iam not making a refernce to test3 class but still its class object gets 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 test3.class file gets created?
.class file was created at compilation time. But, it will be loaded from .class file by first usage (probably).
From where it should be loaded without .class file?)