![]() |
#2
幻紫灵心2018-09-13 12:06
|

class Thread1 implements Runnable
{
int i=10;
public void run()
{
for(;i>0;)
{
System.out.printf("day"+"\n");
i--;
}
}
}
class Thread2 implements Runnable
{
int j=10;
public void run()
{
for(;j>0;)
{
System.out.printf("night"+"\n");
j--;
}
}
}
public class MyThread
{
public static void main(String []args)
{
Thread1 day = new Thread1();
Thread2 night = new Thread2();
Thread thread1 , thread2;
thread1 = new Thread(day);
thread2 = new Thread(night);
thread1.start();
thread2.start();
for(int k=0;k<10;k++)
{
System.out.printf("main thread..."+"\n");
}
}
}
{
int i=10;
public void run()
{
for(;i>0;)
{
System.out.printf("day"+"\n");
i--;
}
}
}
class Thread2 implements Runnable
{
int j=10;
public void run()
{
for(;j>0;)
{
System.out.printf("night"+"\n");
j--;
}
}
}
public class MyThread
{
public static void main(String []args)
{
Thread1 day = new Thread1();
Thread2 night = new Thread2();
Thread thread1 , thread2;
thread1 = new Thread(day);
thread2 = new Thread(night);
thread1.start();
thread2.start();
for(int k=0;k<10;k++)
{
System.out.printf("main thread..."+"\n");
}
}
}
Thread1 day = new Thread1();
Thread2 night = new Thread2();
Thread thread1 , thread2;
thread1 = new Thread(day);
thread2 = new Thread(night);
thread1.start();
thread2.start();
这一段不能直接调用而是thread1 = new Thread(day);样的,小白求教,不懂其中的原理????????