Thread & Runnable

public class ThreadDemo1 {
    public static void main(String[] args) {
        MyThread myThread = new MyThread();
        MyRunnable myRunable = new MyRunnable();
        Thread thread = new Thread(myRunable);
        
        myThread.start();
        thread.start();
    }

}
class MyThread extends Thread{
    @Override
    public void run() {
        System.out.println("MyThread.run()");
    }
    
    @Override
    public synchronized void start() {
        System.out.println("MyThread.start()");
    }
}

class MyRunnable implements Runnable{

    @Override
    public void run() {
        System.out.println("MyRunnable.run()");
    }
    
    public void start(){
        System.out.println("MyRunnable.start()");
    }

}

print:

MyThread.start()
MyRunnable.run()

 

 
posted on 2013-06-01 22:01  洛易  阅读(156)  评论(0编辑  收藏  举报