The constructor Date() is undefined

来源:互联网 发布:linux下vi保存退出 编辑:程序博客网 时间:2024/06/04 18:04

import java.util.Date;// notification: don't   import java.sql.Date.*;public class TestInterrupt {public static void main(String[] args) {Thread3 thread =new TestInterrupt().new Thread3();//** a instance must be The type of TestInterruptthread.start();try {Thread.sleep(10000);} catch(InterruptedException e ) {thread.interrupt();}}class Thread3 extends Thread {boolean flag = true;//end the thread  boolean flag= falsepublic void run() {while(flag) {System.out.println("the latest time is:"+ new Date() +" good morning!"); try {sleep(1000);} catch(InterruptedException e) {return;}}}}}

原因:应该导入util包,而非sql;

   Myelicpse.10有时会自动  import java.sql.Date;

故应改为   import java.util.Date;

      即可成功运行程序。


阅读全文
0 0
原创粉丝点击