我糊涂了.
假设我们有以下课程:
class Shape { /* ... */ }
class Square extends Shape { /* ... */ }
Run Code Online (Sandbox Code Playgroud)
什么是由此产生的布尔值,为什么会这样呢?
Shape shape = ...;
boolean b1 = shape instanceof Square;
Square square = ...;
boolean b2 = ((Shape) square) instanceof Square;
boolean b3 = shape instanceof Object;
Run Code Online (Sandbox Code Playgroud)
据我所知,子类是父类的实例,但不是相反?