example19_1.java

来自「一个十分好的java基础学习的课件」· Java 代码 · 共 28 行

JAVA
28
字号
public class Example19_1
{   static Lefthand left;
    static Righthand right;
    public static void main(String args[ ])
    {   left=new Lefthand( );
        right=new Righthand( );    //创建两个线程
        left.start( );
        right.start( );
    }
}
class  Lefthand extends Thread
{   public void run( )
    {   for(int i=0;i<=5;i++)
        {   System.out.println("i am Lefthand");
            try{sleep(500);}
            catch(InterruptedException e) {   }
        }
    }
}
class Righthand extends Thread
{   public void run( )
    {   for(int i=0;i<=5;i++)
        {   System.out.println("i am Righthand");
            try{sleep(300);}
            catch(InterruptedException e) {   }
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?