当前位置: 技术问答>java相关
下面的程序Compilation error ,如何改!
来源: 互联网 发布时间:2015-06-15
本文导语: public class ThrowsDemo { static void throwMethod() { System.out.println("Inside throwMethod."); throw new IllegalAccessException("demo"); } public static void main(String...
public class ThrowsDemo {
static void throwMethod() {
System.out.println("Inside throwMethod.");
throw new IllegalAccessException("demo");
}
public static void main(String args[]) {
try {
throwMethod();
} catch (IllegalAccessException e) {
System.out.println("Caught " + e);
}
}
}
|
public class ThrowsDemo {
static void throwMethod() throws IllegalAccessException{
System.out.println("Inside throwMethod.");
throw new IllegalAccessException("demo");
}
public static void main(String args[]) {
try {
throwMethod();
} catch (IllegalAccessException e) {
System.out.println("Caught " + e);
}
}
}
这样就好了嘛!
static void throwMethod() throws IllegalAccessException{
System.out.println("Inside throwMethod.");
throw new IllegalAccessException("demo");
}
public static void main(String args[]) {
try {
throwMethod();
} catch (IllegalAccessException e) {
System.out.println("Caught " + e);
}
}
}
这样就好了嘛!
|
static void throwMethod() throws IllegalAccessException {
System.out.println("Inside throwMethod.");
}
System.out.println("Inside throwMethod.");
}
|
或者:
static void throwMethod() throws IllegalAccessException {
System.out.println("Inside throwMethod.");
throw new IllegalAccessException("demo");
}
static void throwMethod() throws IllegalAccessException {
System.out.println("Inside throwMethod.");
throw new IllegalAccessException("demo");
}