以下java程序不能运行,在不改动class Test的前提下,能不能编辑正确呢?请各位大虾帮忙,万分感谢!  
 
  class AException extends Exception{
     public AException(){  
    super();
    } 
    public String toString(){ 
    String aa = "aaaaaaaa";
    return aa; 
    }
    }
  
    class TestException{ 
    void fund(int i)throws AException { 
    if(i==0)
    throw new AException(); 
    }
    }
  
    class Test{ 
    public static void main(String[] arg){
    TestException xx = new TestException(); 
    xx.fund(0);
    } 
    }

解决方案 »

  1.   

     你的fund函数抛出了异常,而你main函数中没有处理异常,也没有把异常抛出,那编译器肯定报错的!
      所以不改变Test不能编译正确。
     
      除非让fund函数不抛异常!
      

  2.   

    对xx.fund(0);一定要try catch,或者让main函数抛出异常
      

  3.   

    要么让main函数抛出异常要么对fund函数try catch
      

  4.   

    class AException extends Exception
    改成class AException extends RuntimeException
      

  5.   

    我已经找到答案啦,谢谢各位,哈哈!~~~
    答案是将TestException用try/catch包住:
        class TestException {     void fund(int i) {     if(i==0)
      try {
       throw new AException();
      } catch (AException e) {
       e.printStackTrace();
      }     }    }
      

  6.   


    这个你也想的出来,明显是高手。请问为什么运行时会出现这个提示呢?
    Exception in thread "main" aaaaaaaa
    at TestException.fund(TestException.java:4)
    at Test.main(Test.java:4)
      

  7.   

    OMG!你不是故意throw new AException()的么
      

  8.   

    不一定啊,除了Test类,另外两个文件都可以改动。