Menu
Topics Index
...
`

About Thread2497


If you need explanation Read this topic

If you need Answer Take test on this topic

About Thread2497
What will be the output of the following program?
public class Opticals {
    public static void main(String[] args) {
        System.out.print("Output");
        new Opticals().doSomething();
    }
    public void doSomething() {
        final int i = 5;
        Thread t = new Thread(new Runnable() {
            public void run() {
                for (int j = 0; j <= i; j++) {
                    System.out.print("~" + j);
                }
            }
        });
        t.start();
    }
}

A. (EMPTY)
B. Output~0~1~2~3~4
C. Output~0~1~2~3~4~5
D. Some other output
E. 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 : e
interface for runnable not implemented
so compilation error

Posted by Ananda Kumar    2014-06-03 12:57:10


C is ans.as calling dosomething method thread is created and started with i value as final whch dsnt change.and thrgh sequential iterating j values r printed.

Posted by Shabaaz Shaikz    2014-06-03 13:11:37


ANS : C, methods should not start with CAPITAL LETTERS ( "new Optical().doSomething()" ) and "new" keyword.

Posted by Damu Surya    2014-06-03 13:28:37


Answer: E
Runnable interface is not implemented

Posted by Sreemukha Taduru    2014-06-03 14:03:52


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

Posted by Merit Campus    2014-06-04 04:50:03


© meritcampus 2019

All Rights Reserved.

Open In App