标题: 这样写有区别吗!?大家说说 [打印本页] 作者: 黑马吕世成 时间: 2012-11-3 19:18 标题: 这样写有区别吗!?大家说说 class Test
{
String str = new String("");
}
class ThreadOne extends Thread
{
Test tt = new Test();
public void run()
{
int i = 0;
while(i<3)
{
System.out.println("ThreadOne str = "+tt.str);
i++;
}
}
public ThreadOne(Test tt)
{
this.tt = tt;//tt = tt
}
}
class ThreadTwo extends Thread
{
Test tt = new Test();
public void run()
{
int i = 0;
while(i<3)
{
i++;
System.out.println("ThreadTwo str = "+tt.str);
}
}
public ThreadTwo(Test tt)
{
this.tt = tt;//tt = tt
}
}
class Main
{
public static void main(String[] args)
{
Test tt = new Test();
new ThreadOne(tt).start();
try{Thread.sleep(10);}catch(Exception e){}
new ThreadTwo(tt).start();
}