public class Test {
public static void main(String[] args) {
Students S = new Students();
try {
S.setAge(10);
} catch (AgeNotFu ag) {
System.out.println(ag.getMessage());
}
}
}
class Students {
int age;
public void setAge(int age) {
if (age < 0) {
throw new AgeNotFu("䲻Ϊ");
}
this.age = age;
System.out.println("óɹ");
}
}
class AgeNotFu extends RuntimeException {
AgeNotFu(String message) {
super(message);
}
}
评论列表( 0 )
你可以在登录后,发表评论