实现Runnable接口,需履盖run()
public class SecondThread implements Runnable
{
public static void main(String[] args)
{
SecondThread st=new SecondThread();
Thread t=new Thread(st);//在此处与继承Thread不同,
t.start();
print("main");
}
public void run(){
print("thread");
}
public static void print(String s)
{
try
{
for (int i=0;i<10 ;i++ )
{
Thread.sleep(1000);//暂停一秒钟
System.out.println(s+i);
}
}catch(Exception e){}
}
}