package com.company.innerclass;
public class TestInnerClass {
public static void main(String[] args) {
//extends Thread类的写法
//new Thread().start();
new Thread(){
@Override
public void run() {
for (int i = 0; i < 20; i++) {
System.out.println(Thread.currentThread().getName()+" extends Thread类的写法");
}
}
}.start();
//implements Runnable类的写法
Runnable r = new Runnable(){
@Override
public void run() {
for (int i = 0; i < 20; i++) {
System.out.println(Thread.currentThread().getName()+" implements Runnable类的写法");
}
}
};
new Thread(r).start();
//implements Runnable类的简写
new Thread(new Runnable(){
@Override
public void run() {
for (int i = 0; i < 20; i++) {
System.out.println(Thread.currentThread().getName()+" implements Runnable类的简写");
}
}
}).start();
}
}
网友评论