Knowee
Questions
Features
Study Tools

What will be the output of the program?class MyThread extends Thread { public static void main(String [] args) { MyThread t = new MyThread(); /* Line 5 */ t.run(); /* Line 6 */ } public void run() { for(int i=1; i < 3; ++i) { System.out.print(i + ".."); } }}This code will not compile due to line 5.This code will not compile due to line 6.1..2..1..2..3..[#]

Question

What will be the output of the program?class MyThread extends Thread { public static void main(String [] args) { MyThread t = new MyThread(); /* Line 5 / t.run(); / Line 6 */ } public void run() { for(int i=1; i < 3; ++i) { System.out.print(i + ".."); } }}This code will not compile due to line 5.This code will not compile due to line 6.1..2..1..2..3..[#]

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

The output of the program will be "1..2..". This is because the run() method is called directly on the MyThread object t at line 6. The run() method then executes on the main thread and prints "1.." and "2..". The program does not create a new thread of execution.

Similar Questions

What will be the output of the program?class MyThread extends Thread { public static void main(String [] args) { MyThread t = new MyThread(); t.start(); System.out.print("one. "); t.start(); System.out.print("two. "); } public void run() { System.out.print("Thread "); }}Compilation failsAn exception occurs at runtime.It prints "Thread one. Thread two."The output cannot be determined

What will be the output of the program?class MyThread extends Thread { MyThread() {} MyThread(Runnable r) {super(r); } public void run() { System.out.print("Inside Thread "); } } class MyRunnable implements Runnable { public void run() { System.out.print(" Inside Runnable"); } } class Test { public static void main(String[] args) { new MyThread().start(); new MyThread(new MyRunnable()).start(); } }Prints "Inside Thread Inside Thread"Prints "Inside Thread Inside Runnable"Does not compileThrows exception at runtime

Select the correct answerWhat is the output of the following program?class Nptel extends Thread { public void run() { System.out.println("Running"); }}public class ThreadTest { public static void main(String args[]) throws Inter ruptedException { Runnable r = new Nptel(); Thread myThread = new Thread(r); myThread.start(); }}Options“Running”Compiler ErrorRuntime ExceptionNo output, but no error

What will be the output of the following Java code?class multithreaded_programing { public static void main(String args[]) {Thread t = Thread.currentThread();System.out.println(t); } } Thread[5,main]Thread[main,5]Thread[main,0]Thread[main,5,main]

Select the correct answerWhat will be the output of the following Java code?class newthread extends Thread { Thread T; newthread() { T = new Thread(this,"T1"); T.start(); } public void run() { try { T.join() System.out.println(T.getName()); } catch(Exception e) { System.out.print("Exception"); } } } class multithreaded_programing { public static void main(String args[]) { new newthread(); } }OptionsExceptionThread[My Thread,5,main] My ThreadRuntime Error

1/4

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.