-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThread7.java
More file actions
38 lines (27 loc) · 775 Bytes
/
Thread7.java
File metadata and controls
38 lines (27 loc) · 775 Bytes
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
// you can override start method
// but that will prevent a thread start
// so lets call parent class start()
// child gets executed immediately
// you can overload run() but Thread class start() will always invoke run() with no arg
class Printer extends Thread {
public void start(){
super.start();
}
public void run(){
for(int i=0; i<100; i++){
System.out.println("From child thread: "+i);
}
}
public void run(int i){
System.out.println("Here comes overload");
}
}
class Main{
public static void main(String[] args){
Printer print = new Printer();
print.start();
for(int i=0; i<10; i++){
System.out.println("From Main thread: "+i);
}
}
}