Knowee
Questions
Features
Study Tools

correct answerPredict the output of following Java Programs.public class Physics extends Thread {    public static void main(String[] args)     {        try         {            Thread t = new Thread(new Physics());            Thread t2 = new Thread(new Physics());        }        catch (Exception e)         {            System.out.print("e ");        }    }    public void run()     {        for (int i = 0; i < 2; i++)         {            try             {                Thread.sleep(500);            }            catch (Exception e)             {                System.out.print("e2 ");            }            System.out.print(Thread.currentThread().getName()+ " ");        }    }}Optionseno outpute2compilation fails

Question

correct answerPredict the output of following Java Programs.public class Physics extends Thread {    public static void main(String[] args)     {        try         {            Thread t = new Thread(new Physics());            Thread t2 = new Thread(new Physics());        }        catch (Exception e)         {            System.out.print("e ");        }    }    public void run()     {        for (int i = 0; i < 2; i++)         {            try             {                Thread.sleep(500);            }            catch (Exception e)             {                System.out.print("e2 ");            }            System.out.print(Thread.currentThread().getName()+ " ");        }    }}Optionseno outpute2compilation fails

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

Solution

The correct answer is "no output".

Here's why:

The Java program creates two threads, t and t2, but it never starts them. In Java, creating a thread and starting

Similar Questions

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

Select the correct answerWhat is the output of the following program?public class Test extends Thread implements Runnable{  public void run()  {    System.out.printf("CT ");  }  public static void main(String[] args) throws InterruptedException  {    Test obj = new Test();    obj.run();    obj.start();  }}OptionsRuntime errorCompilation errorCT CTNone of the above

Select the correct answerWhat is the output in the following Java program?class Main{  public static void main(String args[])  {    Thread t = Thread.currentThread();    System.out.println(t.isAlive());       }}Options0truefalse1

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]

elect the correct answerWhat will be the output of the following Java code?class Main{  public static void main(String args[])  {    Thread t = Thread.currentThread();    t.setName("New Thread");    System.out.println(t);        }}OptionsThread[main,5,main]Thread[New Thread,5]Thread[5,main]Thread[New Thread,5,main]

1/3

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.