线程的睡眠

       用throws抛异常的时候,如果向主调处抛异常的方法是从父类继承的或者是从接口实现的,那么,覆盖父类方法或实现接口方法时,如果父类中的原方法或接口中的原抽象方法没有抛异常,则子类覆盖父类的方法或实现接口的方法也不能抛异常。
       当出现这种情况时,只能try...catch,大不了catch中什么都不写


public class Test{
	public static void main(String[] args){
	    Xc1 xc=new Xc1();
	    Thread ccc=new Thread(xc);
	    ccc.start();
		
	}
}

class Xc1 implements Runnable{
	public void run(){
		for(int i=0;i<10;i++){
			System.out.println(Thread.currentThread().getName()+"   "+i);
			try{
				Thread.sleep(1000);//1000毫秒=1秒
			}
			catch(Exception e){
				
			}
		}
	}
	
}

猜你喜欢

转载自blog.csdn.net/WYJ____/article/details/82555562