我用代码解释下,有什么问题,请指正。
package myThread;
class MyRun implements Runnable {//s实现接口 覆盖run方法
@Override
public void run() {
// TODO Auto-generated method stub
System.out.println("XXX");
}
}
class MyThread extends Thread {//继承覆盖run方法
public void run(){
System.out.println("ZZZ");
}
}
public class Thread3Test {
public static void main(String[] args){
MyRun mr=new MyRun();
mr.run();
MyThread mt=new MyThread();
mt.start();
//一下介绍几种启动线程的方法
Thread th=new Thread(){
public void run(){
System.out.println("YYY");
}
};
th.start();
Thread th1=new Thread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
System.out.println("WWW");
}
});
th1.start();
new Thread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
System.out.println("VVV");
}
}).start();
}
} |