【发布时间】:2016-04-07 07:08:01
【问题描述】:
以下代码编译正常:
interface Flyer{ }
class Bat { }
public class App {
public static void main(String[] args) {
Bat b = new Bat();
if(b instanceof Flyer) System.out.println("b is a Bird");
}
}
如果我们将Bat 类设为final,则代码无法编译:
final class Bat { }
如果最终类实现Flyer,则编译正常:
final class Bat implements Flyer { }
有人愿意解释这背后的逻辑吗?
【问题讨论】:
标签: java