【简答题】
自定义异常,数值不能为负数。(注意:字母大小写、符号中西文必需和标准答案严格一致,不要有多余空格!建议在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; }}
手机使用
分享
复制链接
新浪微博
分享QQ
微信扫一扫
微信内点击右上角“…”即可分享
反馈
收藏
举报
参考答案:
参考解析: