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

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© azhuang 中级黑马   /  2015-11-6 22:43  /  669 人查看  /  4 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

class FuShuIndexExecption extends Exception
{       
         FuShuIndexException(){}
         FuShuIndexException(String s)
        {
                super(s);
        }
}
class Person
{
        public int show(int[] arr,int index)
        {
                if(arr==null)
                        throw new NullPointerException("数组角标不能为空");
               
                if(index>=arr.length)
                {
                        throw new ArrayIndexOutOfBoundsException("数组角标越界啦");
                }
                if(index<0)
                {
                        throw new FuShuIndexException();
                }
                return(arr[index]);
               
        }
}
class ExceptionDemo5
{
        public static void main(String[] args)
        {
                int[] arr = new int[3];
                Person p = new Person();
                //arr =null;
                p.show(arr,-3);
       
                //ExceptionDemo5.method(arr,3);
               
        }
        /*
        public static void method(int[] arr,int index)
        {
                System.out.println(arr[index]);
        }
        */
}

4 个回复

倒序浏览
F:\JAVA1010\day6>javac ExceptionDemo5.java ExceptionDemo5.java:3: 错误: 方法声明无效; 需要返回类型          FuShuIndexException(){}          ^ ExceptionDemo5.java:4: 错误: 方法声明无效; 需要返回类型          FuShuIndexException(String s)          ^ 2 个错误
回复 使用道具 举报
没人吗?帮忙看下
回复 使用道具 举报
class FuShuIndexExecption extends Exception
{      
                        FuShuIndexExecption(){}
                        FuShuIndexExecption(String s)
        {
                super(s);
        }
}
你的构造函数名"FuShuIndexException"中"Ex ception"不对 你的是应该是"Ex ecption"
回复 使用道具 举报
请指教 发表于 2015-11-8 10:28
class FuShuIndexExecption extends Exception
{      
                        FuShuIndexExecption(){}

恩 。。确实是这样。谢了{:2_33:}
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马