匿名内部类创建线程

package chapter1;

public class Demo2 {
    public static void main(String[] args) {
//        Runnable runnable = new Runnable() {
//            @Override
//            public void run() {
//                for (int i = 0; i < 100; i++) {
//                    System.out.println(Thread.currentThread().getName() + i);
//                }
//            }
//        };
////        Thread thread = new Thread("匿名内部类线程");
//        Thread thread = new Thread(runnable, "匿名内部类线程");
////        Thread thread = new Thread(runnable);
//        thread.start();

        Thread thread1 = new Thread() {
            @Override
            public void run() {
                for (int i = 0; i < 100; i++) {
                    System.out.println(Thread.currentThread().getName() + ": " + i);
                }
            }
        };
        thread1.start();
    }
}

发布了55 篇原创文章 · 获赞 15 · 访问量 7万+

猜你喜欢

转载自blog.csdn.net/qq_43141611/article/details/105638969