public abstract class GetTime {
public final void getMyTime(){
long startTime=System.currentTimeMillis();
runCode();
long endTime=System.currentTimeMillis();
System.out.println((endTime-startTime));
}
public abstract void runCode();
}
class SubTime extends GetTime{
//由子类决定获取运行哪段程序的时间
@Override
public void runCode() {
// TODO Auto-generated method stub
for(int i=0;i<1000;i++){
System.out.println(i);
}
}
}
public final void getMyTime(){
long startTime=System.currentTimeMillis();
runCode();
long endTime=System.currentTimeMillis();
System.out.println((endTime-startTime));
}
public abstract void runCode();
}
class SubTime extends GetTime{
//由子类决定获取运行哪段程序的时间
@Override
public void runCode() {
// TODO Auto-generated method stub
for(int i=0;i<1000;i++){
System.out.println(i);
}
}
}