题
MyException extends Exception{
MyException(String abc,int i)
{
Exception(abc);
}
}
为什么要显式调用基类构造器呢?基类不是有默认无参构造器
有无参的。。。看看API吧
继承Exception使用构造器的问题
答案:2 悬赏:20
解决时间 2021-04-22 08:11
- 提问者网友:無奈小影
- 2021-04-22 00:07
最佳答案
- 二级知识专家网友:如果这是命
- 2021-04-22 01:24
没有吧
只有带参的
只有带参的
全部回答
- 1楼网友:我们只是兮以城空
- 2021-04-22 01:31
public class myclass {
private static final int string_length = 10;
public static void main(string[] args) {
string s;
try {
s = getstring();
} catch (stringlengthtoolargeexception e) {
e.printstacktrace();
s = "error";
}
system.out.println(s);
}
private static string getstring() throws stringlengthtoolargeexception {
string s = new scanner(system.in).next();
if (s.length() > string_length) {
throw new stringlengthtoolargeexception();
}
return s;
}
}
class stringlengthtoolargeexception extends exception {
public stringlengthtoolargeexception() {
super("字符串长度超过设定长度");
}
}
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯