黑马程序员技术交流社区

标题: 继承的一点问题 [打印本页]

作者: 彭盼    时间: 2012-3-2 10:39
标题: 继承的一点问题
本帖最后由 彭盼 于 2012-3-2 10:45 编辑

我学到继承相关知识点时,跟随老师写了个小程序:
abstract class GetTime
{
        public final void getTime()//严禁复写
        {
                long start=System.currentTimeMillis();
                runcode();
                long end=System.currentTimeMillis();
                System.out.println("毫秒:"+(end-start));
        }
        public abstract void runcode();
}
class SubTime extends GetTime
{       
        public void runcode()
        {
                for (int x=0;x<6000;x++)
                {
                        System.out.println("x");
                }
}

class  TemplateDemo
{
        public static void main(String[] args)
        {
                SubTime sub=new SubTime();
                sub.getTime();
        }
}
结果运行后,程序老是提示到最后一行进行语法分析已到达文件结尾:
[attachimg]885[/attachimg

未命名.jpg (12.12 KB, 下载次数: 34)

未命名.jpg

作者: 张开开    时间: 2012-3-2 10:47
类要放到TemplateDemo类中,你的{}不匹配,你检查下
作者: 姚鑫    时间: 2012-3-2 10:53
代码验证完毕,没有问题。可能是书写错误,少了个 } 吧。
作者: 刘刚洪    时间: 2012-3-2 13:33
class SubTime extends GetTime
{        
        public void runcode()
        {
                for (int x=0;x<6000;x++)
                {
                        System.out.println("x");
                }
}

上面少了个“}”,刚开始也遇到过这样的问题
作者: 欧阳博    时间: 2012-3-2 13:37
{:soso_e163:}  建议楼主用eclipse开发工具。
作者: 戚雪晖    时间: 2012-3-2 13:49
很明显少了个括号:
class SubTime extends GetTime
{      
        public void runcode()
        {             -------》他对应的少了一个啊
                for (int x=0;x<6000;x++)
                {
                        System.out.println("x");
                }
}
作者: 王杰    时间: 2012-3-2 15:31
SubTime类差一个“}”




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2