What would happen on compiling and running the following code?
public class Test
{
public static void main (String args[])
{
TestThread t = new TestThread ();
t.setValue (5);
t.start ();
t.setValue (10);
}
}
class TestThread extends Thread
{
private int value;
synchronized public void setValue (int v)
{
value = v;
}
public void run ()
{
System.out.println ("before: " + value);
setValue (50);
System.out.println ("after: " + value);
}
}
Correct Answer: When run, this code will always print ''before: 5'' and ''after: 10''
Explanation:
Note: This Question is unanswered, help us to find answer for this one
More Java MCQ Questions