Problem statement:
what will be the output of the following code?
- public class ExecutionFourteen extends Thread {
- private int count;
- private ExecutionFourteen(int count) {
- this.count = count;
- }
- @Override
- public void run() {
- for (int i = 1; i < 4; i++) {
- count = count + 1;
- System.out.println("count inside run() method: " + count + ", thread name: " + Thread.currentThread().getName());
- }
- }
- public static void main(String[] args) {
- ExecutionFourteen t = new ExecutionFourteen(10);
- t.start();
- System.out.println("count inside main() method: " + t.count);
- }
- }
Output:
count inside main() method: 10
count inside run() method: 11, thread name: Thread-0
count inside run() method: 12, thread name: Thread-0
count inside run() method: 13, thread name: Thread-0
No comments:
Post a Comment