class A { System.out.println("start"); Thread.sleep(1000); System.out.println("end"); }
红颜莎娜
浏览 117回答 3
3回答
莫回无
public class TestStaticAera {static{System.out.println("start");try {Thread.sleep(1000);} catch (InterruptedException e) {e.printStackTrace();}System.out.println("end");}}类里面可以存在静态块,在块里面可以写语句,类似上面。但是缺少了main方法,在执行的时候就会提示java.lang.NoSuchMethodError: mainException in thread "main" 。添加main方法,就不会报错了。