class StaticCode
{
static
{
System.out.println("c");
}
{
System.out.println("d");
}
public static void show()
{
System.out.println("show run");
}
}
class StaticCodeDemo
{
static
{
System.out.println("a");
}
public static void main(String[] args)
{
new StaticCode(); //不同点
System.out.println("Hello World!");
}
static
{
System.out.println("b");
}
}
运行结果:
a
b
c
d
Hellow World
class StaticCode
{
static
{
System.out.println("c");
}
{
System.out.println("d");
}
public static void show()
{
System.out.println("show run");
}
}
class StaticCodeDemo
{
static
{
System.out.println("a");
}
public static void main(String[] args)
{
StaticCode.show();//不同点
System.out.println("Hello World!");
}
static
{
System.out.println("b");
}
}
运行结果
a
b
c
show run
Hellow World