java:多线程(匿名内部类实现线程的两种方式)

版权声明:本文为博主原创文章,未经博主允许不得转载 https://blog.csdn.net/qq_24644517/article/details/84292516
public class Demo4_Thread {

	public static void main(String[] args) {
		new Thread() {//1.继承Thread类
			public void run() {//2.重写run方法
				for(int i=0;i<1000;i++) {//3.将要执行的代码,写在run方法中
					System.out.println("aaaaaaa");
				}
			}
		}.start();//开启线程
		
		
		new Thread(new Runnable() {//1.将Runnable的子类对象传递给Thread的构造方法
			@Override
			public void run() {//2.重写run方法
				for(int i=0;i<1000;i++) {//3.将要执行的代码,写在run方法中
					System.out.println("bbbbb");
				}
			}
		}).start();//开启线程
	}

}

猜你喜欢

转载自blog.csdn.net/qq_24644517/article/details/84292516