package demo.oo;
abstract class MyRunTime {
protected final void getTime() {
long startTime = System.currentTimeMillis();
long startTime2 = System.nanoTime();
code();
long endTime = System.currentTimeMillis();
long endTime2 = System.nanoTime();
System.out.println("毫秒" + (endTime - startTime));
System.out.println("纳秒" + (endTime2 - startTime2));
}
protected abstract void code();
}
class TestMyRunTime extends MyRunTime {
public static void main(String[] args) {
new TestMyRunTime().getTime();
}
protected void code() {
for (int i = 0; i < 1002; i++) {
System.out.println(i);
}
}
}