hi,
Please see the following code: please let me know how variable i was been able to get called when actually object a1 had no reference in it i.e. it has null value.
class A1
{
static int i = 10;
static { System.out.println("A1 Loaded "); }
}
public class A
{
static { System.out.println("A Loaded "); }
public static void main(
String[] args)
{
System.out.println(" A should have been loaded");
A1 a1 = null;
System.out.println(" A1 should not have been loaded");
System.out.println(a1.i);
}
}
output:
When you run it you get the output:
A Loaded
A should have been loaded
A1 should not have been loaded
A1 Loaded
10
Any kind of help would be appreciated.