Problem statement: Given code is
First thread: 1
Second thread: 1
Third thread: 1
- public class Test extends Thread {
- private volatile int i = 0;
- public int getData() {
- return i + 1;
- }
- public void run() {}
- public static void main(String[] args) {
- Test t1 = new Test();
- t1.start();
- System.out.println("First thread: " + t1.getData());
- Test t2 = new Test();
- t2.start();
- System.out.println("Second thread: " + t2.getData());
- Test t3 = new Test();
- t3.start();
- System.out.println("Third thread: " + t3.getData());
- }
- }
First thread: 1
Second thread: 1
Third thread: 1
No comments:
Post a Comment