匿名内部类的线程写法

package charpter02;

//匿名内部类
public class TestThread02 {
public static void main(String[] args) {
// 创建一个线程
Thread t = new Thread() {
// 重写线程的方法
@Override
public void run() {
// 遍历线程
for (int i = 0; i <= 100; i++) {
System.out.println("*********");
}
}

};
// 对象调用线程的方法
t.start();
// 创建匿名类
new Thread() {
// 重写Thread类的方法
@Override
public void run() {
// 遍历线程
for (int i = 0; i <= 100; i++) {
System.out.println("%%%%%");
}
}
// 因为匿名内部类直接调用start方法
}.start();

}

}

原文地址:https://www.cnblogs.com/Koma-vv/p/9600203.html