Java 接口特性深入解析
1. 超级接口与子接口关系
接口继承建立了超级接口 - 子接口(也称为超类型 - 子类型)关系。当 CharitySinger 接口继承自 Singer 接口时, Singer 接口是 CharitySinger 接口的超级接口,而 CharitySinger 接口是 Singer 接口的子接口。一个接口可以有多个超级接口,也可以是多个接口的子接口。子接口的引用可以赋值给超级接口的变量。
以下代码展示了超级接口 - 子接口关系的使用:
public interface Shape {
// Code goes here
}
public interface Line extends Shape {
// Code goes here
}
public interface Circle extends Shape {
// Code goes here
}
Shape shape = get an object reference of a Shape...;
Line line = get an object reference of a Line...;
Circle circle = get an object reference of a Circle...;
/* More code goes here... */
shape = line; // Always fine. A L
Java接口特性深入解析与应用
超级会员免费看
订阅专栏 解锁全文
1894

被折叠的 条评论
为什么被折叠?



