public class WithOutMainMethod{
static {
WithOutMainMethod withOutMainMethod=new WithOutMainMethod();
System.out.println("inside static block!");
staticMethod();
withOutMainMethod.nonStaticMethod();
System.exit(0);
}
static void staticMethod(){
System.out.println("inside static method!");
}
void nonStaticMethod(){
System.out.println("inside non static method!");
}
}
output:
inside static block!
inside static method!
inside non static method!
static {
WithOutMainMethod withOutMainMethod=new WithOutMainMethod();
System.out.println("inside static block!");
staticMethod();
withOutMainMethod.nonStaticMethod();
System.exit(0);
}
static void staticMethod(){
System.out.println("inside static method!");
}
void nonStaticMethod(){
System.out.println("inside non static method!");
}
}
output:
inside static block!
inside static method!
inside non static method!
No comments:
Post a Comment