Menu
Topics Index
...
`

Threads1921


If you need explanation Read this topic

If you need Answer Take test on this topic

Threads1921
What will be the output of the following program?
public class HowMayTimes implements Runnable {
    int k = 0;
    public HowMayTimes(int i) {
        k = i;
    }
    public static void main(String[] args) {
        new HowMayTimes(2).run();
        new HowMayTimes(1).run();
    }
    public void run() {
        for (int i = 0; i < k; i++)
            System.out.println("Simple Question");
    }
}

A. Simple Question
Simple Question
Simple Question
B. Simple Question
Simple Question
C. Simple Question
D. Some other output
E. Output can not determined
F. Compilation Error or Runtime Error
Topic: What is Multitasking and Multithreading?

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

ans :a
first thread run functions prints two time
another prints onetime

Posted by Ananda Kumar    2014-05-12 08:48:02


ans is A: because in main func, new HowmanyTimes calling as 2+1 times..,totally 3 times it prints.

Posted by Saikiran Vavilala    2014-05-12 08:48:36


Ans is A as k ivalue is 2 and 1 is passed to  HowmayTimes() function in main and in run method "SImple Question" is printed 3 times and as thread is created as HowMayTimes class implements Runnable interface

Posted by Bharath Yelchuri    2014-05-12 12:34:27


Congratulations Ananda Kumar. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-05-13 04:13:49


© meritcampus 2019

All Rights Reserved.

Open In App