public class Test { static { System.out.println("There is only a static block ,rather than a main method"); } } 唯一的缺陷就是会抛出exception
噢,对了,加上System。exit()就不会有exception了 public class Test { static { System.out.println("There is only a static block ,rather than a main method"); System.exit(0); } }
{
static
{
System.out.println("There is only a static block ,rather than a main method");
}
}
唯一的缺陷就是会抛出exception
public class Test
{
static
{
System.out.println("There is only a static block ,rather than a main method");
System.exit(0);
}
}