By Static Variable
Suppose we have two file Demo.java and Loading.java
Demo.java
What we get static block that mean by calling other class static variable we can load that ".class" file.
By Static Method
Demo.java
That means we can load other .class file by calling static variable as well as static method.
Suppose we have two file Demo.java and Loading.java
Demo.java
class Demo{
static int a=111;
static{
System.out.println("Static Block");
}
}
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);
}
}
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");
}
}
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();
}
}
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.