package com.yang.java;
//创建继承Thread 类的子类
//重写Thread 类的RUN方法
//创建Thread类的子类对象
//调用Start()
public class ArrayTest {
public static void main(String[] args) {
TestDemo ts=new TestDemo();
Thread t=new Thread(ts);
t.start();
}
}
class TestDemo implements Runnable {
@Override
public void run() {
// TODO Auto-generated method stub
for (int i = 0; i < 100; i++) {
if (i%2==0) {
System.out.println(i);
}
}
}
}
比较创建线程的两种方式
开发中,优先选择实现runnable接口,实现的方式更适合来处理多个线程有共享数据的情况
共同点都需要重写run()方法