1package com.tutorialspoint;
2
3import java.lang.*;
4
5public class ThreadDemo implements Runnable {
6
7 Thread t;
8 ThreadDemo() {
9
10 // thread created
11 t = new Thread(this, "Admin Thread");
12
13 // prints thread created
14 System.out.println("thread = " + t);
15
16 // this will call run() function
17 System.out.println("Calling run() function... ");
18 t.start();
19 }
20
21 public void run() {
22 System.out.println("Inside run()function");
23 }
24
25 public static void main(String args[]) {
26 new ThreadDemo();
27 }
28}
1 Thread thread = new Thread(){
2 public void run(){
3 System.out.println("Thread Running");
4 }
5 };
6
7 thread.start();