interface Type1 {
void f() throws CloneNotSupportedException;
}interface Type2 {
void f() throws InterruptedException;
}interface Type3 extends Type1, Type2 {
}public class Arcane3 implements Type3 {
public void f() {
System.out.println("Hello world");
}
public static void main(String[] args) {
Type3 t3 = new Arcane3();
t3.f();
}
}这个程序编译过了。。也能执行出结果。。
有点颠覆我以前的理解了 Type3怎么能继承两个 望解释详细点
还有。。这个里面异常的问题也望能解释解释
void f() throws CloneNotSupportedException;
}interface Type2 {
void f() throws InterruptedException;
}interface Type3 extends Type1, Type2 {
}public class Arcane3 implements Type3 {
public void f() {
System.out.println("Hello world");
}
public static void main(String[] args) {
Type3 t3 = new Arcane3();
t3.f();
}
}这个程序编译过了。。也能执行出结果。。
有点颠覆我以前的理解了 Type3怎么能继承两个 望解释详细点
还有。。这个里面异常的问题也望能解释解释
解决方案 »
- 救急!哪位有birt报表汉化包没有?
- 谁用asp调用过ocx控件?
- JAVA SOCKET服务端接收C客户端字节长度的问题
- 大家讨论一下cxf与wss4j的Timestamp Signature Encrypt配置问题
- 一个小问题,XP改成vista系统后,然后运行的时候,验证码显示不出来啦,下面是异常报告.....
- 如果使用JDOM生成XML文件的同时并且添加本地验证的XSD名称空间
- hibernate “could not execute query” “Table 'user.tab_employee' doesn't exist”
- 快帮我解决问题(tomcat自带的例子怎么运行)吧。:( 解决了100分
- Jbuilder中关联的字段连线问题
- tomcat的work线程占用大量cpu
- float 相乘的问题
- ibatis sqlMap中文乱码
3.Each interface limits the set of checked exceptions that method f can throw. The set of checked exceptions that a method can throw is the intersection of the sets of checked exceptions that it is declared to throw in all applicable types, not the union. As a result, the f method on an object whose static type is Type3 can't throw any checked exceptions at all. Therefore, Arcane3 compiles without error and prints Hello world.
也就是可以抛出的是异常的交集,而不是并集。
参考:java puzzlers-----Puzzle 37: Exceptionally Arcane
也一样的。
"interface Type3 extends Type1, Type2 { } "
这里有点问题:能继承两个接口吗?