Consider the following Java program segment. import java.io.*;public class SomeClass{  public void x() {       throw new RuntimeException("Exception from x");
  }
  
  public void y(){       throw new IOException("Exception from y");
  }
}
Which of the following is true concerning the definitions for the methods x and y? 
 
  (a) Neither x nor y has a legal definition.
 (b) Both x and y have legal definitions.
 (c) x has an illegal definition, but y has a legal definition.
 (d) x has a legal definition, but y has an illegal definition.  
不会做……大侠帮忙~!谢谢~!

解决方案 »

  1.   

    我只知道
    public void y(){  throw new IOException("Exception from y");
      }
    这是错的
    我不知道洋文
      

  2.   

    选D,RuntimeException不需要异常声明,IOException需要
    所以y应该声明为public void y() throws IOException
      

  3.   

    答案是D,因为x抛的是runtime的exception,改异常不catch也是可以滴
    而2抛的不是runtime的exception,需要try 处理,或者在方法体上throws该exception
      

  4.   

    IOException是已检查异常 应该被throws IOException 
    所以选D吧 我说的对吗?请指教