-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqb151.java
More file actions
41 lines (35 loc) · 1.29 KB
/
qb151.java
File metadata and controls
41 lines (35 loc) · 1.29 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
/*
It's IPL 2023 time. In this process of IPL-23 there is a thread called Bowler.
This Bowler is going to create two threads with name – “Yorker” and “googly”.
Write a java program to perform following task with each thread.
Task 1 : if the thread name is "yorker" then it should print "SIXER"
Task 2 : if the thread name is "googly" then it should print "WICKET"
Make sure first thread bowl must be yorker. When execution of first thread is completed
then and only then second bowl googly should work.
Hint: Here Bowler is a Thread Class. and It must have execution of SIXER AND WICKET. Both
yorker and googly must be from Bowler Thread Only.
Give name IPL to the class of Main method.
*/
class Bowler extends Thread {
public void run() {
if (Thread.currentThread().getName().equals("yorker")) {
System.out.println("SIXER");
} else if (Thread.currentThread().getName().equals("googly")) {
System.out.println("WICKET !!");
}
}
}
class IPL {
public static void main(String[] args) {
Bowler t1 = new Bowler();
t1.setName("yorker");
Bowler t2 = new Bowler();
t2.setName("googly");
t1.start();
try {
t1.join();
} catch (Exception e) {
}
t2.start();
}
}