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

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 任雷彬 中级黑马   /  2012-10-25 01:51  /  1749 人查看  /  6 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

public class ReturnExceptionTest
{
        public static void main(String[] args)
        {
                ReturnExceptionTest t = new ReturnExceptionTest();
                System.out.println("调用t.divide(2)方法返回结果:"+t.divide(2));
                }
                public int divide(int i){
                int y =10;
                try
                {
                System.out.println("y="+y+"i="+i);
                int a = y/i;
                return a;
                }
                catch (ArithmeticException e)
                {
                        System.out.println("捕获ArithmeticException异常");
                        e.printStackTrace();
                }
                finally{
                System.out.println("这是finally语句");
                }
                System.out.println("the programe is end");
                return y;
                }
}
上面的try...catch...finally代码编译后报出下面的错误,这个错误是什么意思,代码哪里错了???

/*
Exception.java:1: 错误: 类ReturnExceptionTest是公共的, 应在名为 ReturnExceptionT
est.java 的文件中声明
public class ReturnExceptionTest
       ^
1 个错误
*/
      代码哪里错了???

评分

参与人数 1技术分 +1 收起 理由
韩军博 + 1 神马都是浮云

查看全部评分

6 个回复

倒序浏览

回复 使用道具 举报
楼主,你这个代码我运行了。没有错误啊,你在好好看看,是不是你的类型和你运行的名字不一致。
回复 使用道具 举报
代码没错,应该保存的时候文件名出问题了。
回复 使用道具 举报
public 修饰的类,保存的文件名必须和这个类名相同
回复 使用道具 举报
没有什么错误
回复 使用道具 举报
恩  应该是保存的时候出的错
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马