一、线程的创建
方法一:继承Thread
class MyThread extends Thread{
@Override
public void run(){
System.out.println("hello Thread");
}
}
public class Dome1 {
public static void main(String[] args) {
Thread t=new MyThread();
t.start();
}
}
方法二: 实现 Runnable 接口
class MyRunnable implements Runnable{
@Override
public void run(){
System.out.println("hello Thread");
}
}
public class Dome3 {
public static void main(String[] args) {
Thread t=new Thread(new MyThread());
t.start();
}
}
方法三:匿名内部类创建 Thread 子类对象
public class Dome4 {
public static void main(String[] args) {
Thread t=new Thread(){
@Override
public void run(){
System.out.println("hello Thread");
}
};
t.start(