8 How ".class" file is loading by calling static variables and methods.

By Static Variable 

Suppose we have two file Demo.java and Loading.java

Demo.java

class Demo{
static int a=111;
static{
System.out.println("Static Block");
}

}


Loading.java

public class Loading{

public static void main(String...r)throws Exception{
System.out.println(Demo.a);
}
}


After executing Loading:

What we get static block that mean by calling other class static variable we can load that ".class" file.


By Static Method

Demo.java

class Demo{
static int a=111;
static{
System.out.println("Static Block Demo");
}

static void m1(){
System.out.println("Static m1 method");
}

}


Loading.java

public class Loading{

public static void main(String...r)throws Exception{
Demo.m1();
}
}


After executing Loading:

That means we can load other .class file by calling static variable as well as static method.
Previous
Next Post »