Menu
Question Index
...

What will be out put of the following program?

public class Cruiser {
    private int a = 0;
    public void meth() {
        Runnable r = new LittleCruiser();
        new Thread(r).start();
        new Thread(r).start();
    }
    public static void main(String arg[]) {
        Cruiser c = new Cruiser();
        c.meth();
    }
    public class LittleCruiser implements Runnable {
        public void run() {
            int current = 0;
            for (int i = 0; i < 4; i++) {
                current = a;
                System.out.print(current + ", ");
                a = current + 2;
            }
        }
    }
}


0, 2, 4, 6, 0, 2, 4, 6
0, 2, 4, 6, 8, 10, 12, 14,
0, 2, 4, 6, 8, 10, 2, 4,
0, 0, 2, 2, 4, 4, 6, 6, 8, 8, 10, 10, 12, 12, 14, 14,
0, 2, 4, 6, 8, 10, 12, 14, 0, 2, 4, 6, 8, 10, 12, 14,

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