/*
获得一段程序运行的时间
*/
abstract class GetTime
{
final GetTime() //如何防止GetTime方法被复写?
{
long start = System.currentTimeMillis();
runCode();
long end = System.currentTimeMillis();
System.out.println("Time="+(end - start));
}
public abstract void runCode()
}
class SubGetTime extends GetTime
{
public void runCode()
{
for (int x = 1;x < 2000;x++)
{
System.out.print(x);
}
}
}
class TemplateDemo
{
public static void main(String[] args)
{
new SubGetTime();
}
}