JAVA_多线程基础:run()的使用

尝试定义一个继承Thread的类,并覆盖run方法在run()中每0.1秒打印一句话。“hello,world”

public class Dayin extends Thread{
	
	public void run(){
		while(true){	
			try {
				System.out.println("hello world");
				sleep(100);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	public static void main(String[] args) {
		Dayin dayin=new Dayin();
		dayin.start();

	}

}

发布了36 篇原创文章 · 获赞 26 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/qq_36812792/article/details/80091813