SubThread s1=new SubThread("hehe");
SubThread s2=new SubThread("lala");
new Thread(s1).start();
new Thread(s2)..start();
SubThread s2=new SubThread("lala");
new Thread(s1).start();
new Thread(s2)..start();
正确的是:
class SubThread extends Thread
{
static int i;
public SubThread(String name)
{
super(name);
}
public synchronized void run()
{
for(; i < 30; i++)
{
System.out.println(Thread.currentThread().getName() + "--" + i);
}
}
}
public class MainThread
{
public static void main(String[] args)
{
SubThread s1=new SubThread("hehe");
SubThread s2=new SubThread("lala");
s1.start();
s2.start();
}
}