Home » Java Programming » Threads

What will be the output of the program? class MyThread extends Thread { public static void main(String [] args) { MyThread t = new MyThread(); Thread x = new Thread(t); x.start(); /* Line 7 */ } public void run() { for(int i = 0; i < 3; ++i) { System.out.print(i + ".."); } } }

Correct Answer: 0..1..2..

Explanation:

The thread MyThread will start and loop three times (from 0 to 2).


Option A is incorrect because the Thread class implements the Runnable interface; therefore, in line 7, Thread can take an object of type Thread as an argument in the constructor.


Option B and C are incorrect because the variable i in the for loop starts with a value of 0 and ends with a value of 2.


← Previous Question Next Question→

More Questions from Threads

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion