ThreadDemo.java Source code

Java tutorial

Introduction

Here is the source code for ThreadDemo.java

Source

class ThreadDemo extends Thread {
    public void run() {
        // returns the name of this Thread.
        System.out.println("Name = " + getName());
    }
}

public class Main {
    public static void main(String args[]) {
        Thread t = new Thread(new ThreadDemo(), "java2s.com thread");
        // set thread priority
        t.setPriority(1);
        // print thread created
        System.out.println("thread  = " + t);
        // this will call run() function
        t.start();
    }

}