-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest.java
More file actions
49 lines (36 loc) · 1.14 KB
/
Copy pathTest.java
File metadata and controls
49 lines (36 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
public class Test extends Thread{
// Creating Thread in Java
// by extending thread class
// public void run(){
// System.out.println("thread running");
// }
// public static void main(String[] args) {
// Test t = new Test();
// t.start();
// }
// by implementing runnable interface
// public void run(){
// System.out.println("thread running");
// }
// public static void main(String[] args) {
// Test t = new Test();
// Thread th = new Thread(t);
// th.start();
// }
// by thread class: Thread(String name)
// public static void main(String[] args) {
// Thread th = new Thread("Thread name is bhupendra");
// th.start();
// System.out.println(th.getName());
// }
// using the thread class: Thread(runnable r,String name)
public void run(){
System.out.println("Thread running");
}
public static void main(String[] args) {
Runnable r = new Test();
Thread th = new Thread(r,"thread name is bhupendra");
th.start();
System.out.println(th.getName());
}
}