2019-06-03-toString()直接输出
作者:
陈林晖 | 来源:发表于
2019-06-03 22:43 被阅读0次package test;
class MyException extends Exception {
String id;
public MyException(String str) {
id = str;
}
public String toString() {//toString()方法
return "我是异常:" + id;
}
}
package test;
public class TestException {
public static void main(String a[]) {
try {
throw new MyException("一个测试异常");
} catch (MyException e) {
System.out.println(e);//默认调用toString()--e.toString()--
}
}
}
本文标题:2019-06-03-toString()直接输出
本文链接:https://www.haomeiwen.com/subject/hixkxctx.html
网友评论