A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

© 彭盼 中级黑马   /  2012-3-2 10:39  /  1700 人查看  /  6 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

本帖最后由 彭盼 于 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

评分

参与人数 1技术分 +1 收起 理由
老罗 + 1 很给力!

查看全部评分

6 个回复

倒序浏览
类要放到TemplateDemo类中,你的{}不匹配,你检查下

评分

参与人数 1技术分 +1 收起 理由
老罗 + 1

查看全部评分

回复 使用道具 举报
代码验证完毕,没有问题。可能是书写错误,少了个 } 吧。
回复 使用道具 举报
class SubTime extends GetTime
{        
        public void runcode()
        {
                for (int x=0;x<6000;x++)
                {
                        System.out.println("x");
                }
}

上面少了个“}”,刚开始也遇到过这样的问题
回复 使用道具 举报
{:soso_e163:}  建议楼主用eclipse开发工具。
回复 使用道具 举报
很明显少了个括号:
class SubTime extends GetTime
{      
        public void runcode()
        {             -------》他对应的少了一个啊
                for (int x=0;x<6000;x++)
                {
                        System.out.println("x");
                }
}
回复 使用道具 举报
王杰 黑马帝 2012-3-2 15:31:43
7#
SubTime类差一个“}”
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马