先看一个程序
import java.util.*;
class time{
public static void main(String args[]){
Date d=new Date();//关注
while(true){
System.out.println(d.getSeconds());
try{Thread.sleep(1000);}catch(Exception e){}
}
}
}
这个程序的运行结果都会为一个数,这样涉及对象机制中的一些东西。
修改程序如下:
import java.util.*;
class time{
public static void main(String args[]){
Date d=null;//关注
while(true){
d=new Date();//关注
System.out.println(d.getSeconds());
try{Thread.sleep(1000);}catch(Exception e){}
}
}
}