Java程序有何错误

来源:百度知道 编辑:UC知道 时间:2024/05/26 06:38:10
public class Q1{
public static void main(String args[]){
try {throw new MyException();}
catch (Exception e) {
System.out.println("It's caught!");
}
finally{
System.out.println("It's finally caught!");}
}
class MyException extends Exception{}

public class Q1{

public static void main(String args[]){
try {
Q1 q = new Q1();
throw q.new MyException();
}
catch (Exception e) {
System.out.println("It's caught!");
}
finally{
System.out.println("It's finally caught!");
}
}
class MyException extends Exception{
}
}

正确代码,如果有问题联系HI我

class MyException extends Exception{}这句写在Q1里了,你的Q1少了个}号在class MyException前面加上}号就好啦!

1.缺了大括号
2.class MyException extends Exception{}前面加修饰符static

基本上没看出来对的地方

class MyException extends Exception{] 前面少了一个 }

你是不是用记事本写的, 用工具 一看就看出来了。