定义一个继承Thread类,并覆盖run()方法,并在run()方法中每隔一百毫秒 打印一句话

public class Csh extends Thread{

    public void run(){
        outInfo();
    }

    private void outInfo() {
        for(int i=0;i<21;i++){
            System.out.println("我最聪明");
            
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                
                e.printStackTrace();
            }
        }
        
    }
    
    
    public static void main(String[] args) {
        
        Csh m = new Csh();
        
        m.start();
        
        Csh n = new Csh();
        n.start();
    }
}
原文地址:https://www.cnblogs.com/bianxiaoyan/p/5282047.html