- package com.kxg_08;
- /*
- * 匿名内部类实现多线程
- */
- public class ThreadDemo {
- public static void main(String[] args) {
- // 继承Thread类实现
- Thread t = new Thread() {
- public void run() {
- for (int i = 0; i < 100; i++) {
- System.out.println(getName() + ":" + i);
- }
- }
- };
- t.start();
- // 实现Runnale接口实现
- Thread t2 = new Thread(new Runnable() {
- @Override
- public void run() {
- for (int i = 0; i < 100; i++) {
- System.out.println(Thread.currentThread().getName() + ":"
- + i);
- }
- }
- });
- t2.start();
- }
- }
复制代码
|
|