173.
}
}
Answer:
The code compiles fine and displays the following output:
Inside Run Method.
Name of thread is: My Thread
When Line 1
is executed, it sets the name of the thread to
My
Thread. So, when Line 2 is executed,
it spawns a new thread
and executes the code within the run() method which prints the
name
of the thread as My Thread
Consider the following code:
class TestMyRunnable implements Runnable {
public void run() {
for (int iValue = 0; iValue < 1000; iValue++)
System.out.println(“Name of thread is:
“+Thread.currentThread().getName());
}
public static void main (String argument[]) {
TestMyRunnable runnable = new TestMyRunnable();
Thread threadC = new Thread(runnable);
Thread threadD = new Thread(runnable);
threadC.setName(“Thread 1”);
threadD.setName(“Thread 2”);
threadC.start();
threadD.start();
}
}