Menu
Question Index
...

What will be the output of the following program?

public class HaiBujji implements Runnable {
    private int x;
    private int y;
    public static void main(String[] args) {
        HaiBujji that = new HaiBujji();
        (new Thread(that)).start();
        (new Thread(that)).start();
    }
    public synchronized void run() {
        for (int i = 0; i < 3; i++) {
            x++;
            y++;
            System.out.print(x + " " + y + ", ");
        }
    }    
}


0 0, 1 1, 2 2,
1 1, 2 2, 3 3, 1 1, 2 2, 3 3,
0 0, 1 1, 2 2, 3 3, 4 4, 5 5,
1 1, 2 2, 3 3, 4 4, 5 5, 6 6,
Compilation Error or Runtime Error

Doubts

Problems

Topic: What is Multitasking and Multithreading?

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App