黑马程序员技术交流社区
标题:
关于抽象类的例题
[打印本页]
作者:
李斌
时间:
2012-4-21 23:43
标题:
关于抽象类的例题
为什么打印不出毫秒值哦?
abstract class GetTime
{
public final void getTime()
{
long start = System.currentTimeMillis();
runcode();
/*
for (int x=0;x<1000 ;x++ )
{
System.out.print(x);
}
*/
long end = System.currentTimeMillis();
System.out.println("毫秒:"+(end-start));
}
public abstract void runcode();
}
class SubTime extends GetTime
{
public void runcode()
{
//long start=System.currentTimeMillis();
for (int x=0;x<1000 ;x++ )
{
System.out.print(x);
}
//long end=System.currentTimeMillis();
//System.out.println("毫秒:"+(end-start));
}
}
class TemplateDemo
{
public static void main(String[] args)
{
SubTime gt=new SubTime();
gt.runcode();
}
}
只能打印出x 好疑惑~~
复制代码
作者:
黑马罗坚
时间:
2012-4-21 23:53
本帖最后由 nailsoul 于 2012-4-21 23:56 编辑
abstract class GetTime
{
public final void getTime()
{
long start = System.currentTimeMillis();
runcode();
/*
for (int x=0;x<1000 ;x++ )
{
System.out.print(x);
}
*/
long end = System.currentTimeMillis();
System.out.println("\n毫秒:"+(end-start));
}
public abstract void runcode();
}
class SubTime extends GetTime
{
public void runcode()
{
//long start=System.currentTimeMillis();
for (int x=0;x<1000 ;x++ )
{
System.out.print(x);
}
//long end=System.currentTimeMillis();
//System.out.println("毫秒:"+(end-start));
}
}
class TemplateDemo
{
public static void main(String[] args)
{
SubTime gt=new SubTime();
//这里应该是getTime()函数 有getTime()函数调用runcode()函数
gt.getTime();
}
}
复制代码
作者:
李斌
时间:
2012-4-22 00:04
nailsoul 发表于 2012-4-21 23:53
知道了 谢谢~~:victory:
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2