1.继承Thread 重写run()
MyThread mt=new MyThread();
mt.start();
2.实现RUnnable 重写run()
Runnable ru=new Runnanle();
Thread t=new Thread(ru);
t.start();
1.package demo01;
public class MyThread extends Thread{
@Override
public void run() {
for(int i=0;i<5;i++){
System.out.println("夏明"+i);
}
}
}
package demo01;
public class MyThread2 implements Runnable{
@Override
public void run() {
for(int i=0;i<5;i++){
System.out.println("MyThread2 "+i);
}
}
}
package demo01;
public class Test01 {
public static void main(String[] args) {
Thread my=new MyThread();
my.start();
MyThread2 t=new MyThread2();
Thread t2=new Thread(t);
t2.start();
for(int i=0;i<5;i++){
System.out.println("小李"+i);
}
}
}