问答题
自定义异常,数值不能为负数。(注意:字母大小写、符号中西文必需和标准答案严格一致,不要有多余空格!建议在IDE环境中运行通过后,再将答案粘贴过来。)
public class NoScoreException extends RuntimeException {
public NoScoreException() {
super();
}
public NoScoreException(String message) {
super(message);
}
}
public class Student {
private String name;
private int score;
public Student() {
super();
}
public Student(String name,int score){
setName(name);
setScore(score);
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getScore() {
return score;
}
public void setScore(int score) {
// 判断如果score为负数xxx,就抛出NoScoreException,异常信息为:分数不能为负数:xxx
if(score <0){
;
}
this.score = score;
}
}
答案:
throw new NoScoreException("分数不能为负数:"+score)或throw new NoSco...