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.
不会做……大侠帮忙~!谢谢~!
public void y(){ throw new IOException("Exception from y");
}
这是错的
我不知道洋文
所以y应该声明为public void y() throws IOException
而2抛的不是runtime的exception,需要try 处理,或者在方法体上throws该exception
所以选D吧 我说的对吗?请指教