A)
class b
{
static int a;
static
{
System.out.println(a);
}
}
class c {
public static void main(String[] args) {
System.out.println("I am first");
System.out.println("a :"+b.a);
}
}
Output:
I am first
I am first
0
a :0
->here when 2 classes are there when javac is given to the JVM ‘.class’ of c and b is created.
->Now after execution ‘javac’ is given to JVM.JVM loaded only .class file is loaded the firstly
‘main ()’ is called and ‘I am first’ is printed.
->After that ‘b.a’ is called then ‘b’ class is loaded secondary memory to prim memory and firstly static variable memory is allocated and then static block is executed.
->Default values are then printed and later a=0 is printed.
Comments
Post a Comment