package com.cx.Threads; public class HelloThread extends Thread{ @Override public void run() { for (int i = 0; i < 100; i++) { if(i%2==0){ System.out.println(Thread.currentThread().getName()+":"+i); } } } public HelloThread(){ } public HelloThread(String name){ super(); } }
1 package com.cx.Threads; 2 3 public class Text { 4 public static void main(String [] args ){ 5 HelloThread t1=new HelloThread("线程一"); 6 7 t1.start(); 8 HelloThread t2=new HelloThread(); 9 t2.setName("线程二");//必须在启动start之前 10 t2.start(); 11 } 12 }
经过检查发现是super();应该改成super(name);