package com.haizhitao.thread;
public class ThreadTest
{
public static void main(String[] args)
{
Thread1 thread = new Thread1();
Thread2 thread2 = new Thread2();
thread.start();
thread2.start();
}
}
class Thread1 extends Thread
{
@Override
public void run()
{
for(int i = 0; i < 5; i++)
{
System.out.println("hello world: " + i);
}
}
}
class Thread2 extends Thread
{
@Override
public void run()
{
for(int i = 0; i < 5; i++)
{
System.out.println("welcome:" + i);
}
}
}
//output:(每次运行结果不同)
// hello world: 0
// welcome:0
// welcome:1
// welcome:2
// welcome:3
// welcome:4
// hello world: 1
// hello world: 2
// hello world: 3
// hello world: 4
68
最新推荐文章于 2024-07-16 05:31:46 发布