MainClass.java Source code

Java tutorial

Introduction

Here is the source code for MainClass.java

Source

/*
 * Output: 
    
currentThread: Thread[main,5,main]
Thread created: Thread[Demo Thread,5,main]
5
4
3
2
1
exiting child thread
    
    
 */

public class MainClass implements Runnable {
    MainClass() {
        Thread ct = Thread.currentThread();
        Thread t = new Thread(this, "Demo Thread");
        System.out.println("currentThread: " + ct);
        System.out.println("Thread created: " + t);
        t.start();

    }

    public void run() {
        for (int i = 5; i > 0; i--) {
            System.out.println("" + i);
        }
        System.out.println("exiting child thread");
    }

    public static void main(String args[]) {
        new MainClass();
    }
}