package Exam;

public class ThreadDemo implements Runnable {

	public static void demo() {
		System.out.println("\n\nStarting ThreadDemo.demo()");
		System.out.println("Top thread: " + Thread.currentThread());
		new ThreadDemo("START").doStart();
		new ThreadDemo("RUN").doRun();
	}
	
	String name_;
	
	ThreadDemo(String s) {
		name_ = s;
	}

	/** Run in new Thread
	*/
	public void doStart() {
		new Thread(this).start();
	}
	
	/** Run in parent Thread.
	*/
	public void doRun() {
		new Thread(this).run();
	}
	
	public void run() {
		System.out.println(this + " is thread " + Thread.currentThread());
	}
	
	public String toString() {
		return name_;
	}
}
