Question: explain the code with the output in the box below: class MyThread extends Thread { String message; MyThread ( String message ) { this.message =

explain the code with the output in the box below:
class MyThread extends Thread {
String message; MyThread(String message)
{
this.message = message;
}
public void run()
{
try
{
for(int i=1; i<=5; i++)
{
System.out.println(message +-+ i); Thread.sleep(5000);
}
}
catch(InterruptedException ie){}
}
}
public class MultipleThreadDemo
{
public static void main( String[] args)
{
MyThread t1= new MyThread(One); MyThread t2= new MyThread(Two); System.out.println(t1); System.out.println(t2);
t1.start();
t2.start();
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!