/*
class A extends Thread
{
public void run()
{
try
{
Thread.sleep(1000);
}catch(Exception e)
{
System.out.println("A ERROR!");
}
System.out.println("AAAA");
}
}
class B extends Thread
{
public void run()
{
try
{
Thread.sleep(2000);
}catch(Exception e)
{
System.out.println("B ERROR!");
}
System.out.println("BBBB");
}
}
class C extends Thread
{
public void run()
{
try
{
Thread.sleep(3000);
}catch(Exception e)
{
System.out.println("C ERROR!");
}
System.out.println("CCCC");
}
}
public class Test_1
{
public static void main(String[] args)
{
A a = new A();
B b = new B();
C c = new C();
a.start();
b.start();
c.start();
}
}*/
public class Test_1
{
public static void main(String[] args)
{
A a = new A();
B b = new B();
C c = new C();
Thread ta = new Thread(a);
Thread tb = new Thread(b);
Thread tc = new Thread(c);
ta.start();
tb.start();
tc.start();
}
}
class A implements Runnable
{
public void run()
{
try
{
Thread.sleep(1000);
}catch(Exception e)
{
System.out.println("A ERROR!");
}
System.out.println("AAAA");
}
}
class B implements Runnable
{
public void run()
{
try
{
Thread.sleep(2000);
}catch(Exception e)
{
System.out.println("B ERROR!");
}
System.out.println("BBBB");
}
}
class C implements Runnable
{
public void run()
{
try
{
Thread.sleep(3000);
}catch(Exception e)
{
System.out.println("C ERROR!");
}
System.out.println("CCCC");
}
}
案例一的两种方法已经写好;现在有事,晚上再把案例二代码写一下,应该没关系吧!
抱歉,是一个线程类,我看错了,晚上重发一下代码!
追问没关系
追答
解释:Test_1结果对应第二张图片,(由于线程的不确定性,建议多试几次);
Test_2对应第一张图片。感觉和要求有点不符(票没有卖完),不过我想到的方法就这个了。
代码在压缩包里
本回答被提问者和网友采纳