The question is from http://www.javacertifications.net/javacert/scjp1.6Mock.jsp
Questions no -20
What is the output for the below code ?
public class Test extends Thread
{
static String sName = "good";
public static void main(String argv[])
{
Test t = new Test();
t.nameTest(sName);
System.out.println(sName);
}
public void nameTest(String sName)
{
sName = sName + " idea ";
start();
}
public void run()
{
for(int i=0;i < 4; i++)
{
sName = sName + " " + i;
}
}
}
options A)good B)good idea C)good idea good idea Correct answer is : A
Explanations : Change value in local methods wouldn’t change in global in case of String ( because String object is immutable).