画坦克__线程__V1__第一种方法创造线程

一、代码如下

package www.tainiu.gui__V2;

public class aa__XianCheng__V1 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Cat cat1= new Cat();
		Cat cat2= new Cat();
		cat1.start();
		cat2.start();

	}

}



class Cat extends Thread{
	int times= 0;
	@Override
	public void run() {
		// TODO Auto-generated method stub
		super.run();
		while(true) {
			try {Thread.sleep(1000);} catch (InterruptedException e) {e.printStackTrace();}
			times ++;
			System.out.println("Hello World__"+times+this.getName());
			if(times == 10) {
				break;
			}
		}
		
		
	}
}

 

posted @ 2017-10-06 22:10  18513757531  阅读(142)  评论(0编辑  收藏  举报