Tricky compiler behavior
- by Neeraj
Simple java code snippet. It has three classes. After compiling the code please delete A.class and then execute the code. Code still runs, why its not checking whether the byte code of A exists or not?
class A
{
static
{
System.out.println("In the class A");
}
public A()
{
}
}
class B
{
private A a = null;
static
{
System.out.println("In the class B");
}
public B()
{
a = new A();
}
}
public class ExampleLinkage
{
static
{
System.out.println("In the class A");
}
public ExampleLinkage(String str)
{
}
public static void main(String args[])
{
try
{
System.out.println("In the main method of ExampleLinkage");
Class.forName("com.bt.rtti.B");
}
catch(Exception e)
{
e.printStackTrace();
}
}
}