在这样的层次结构中,类基于其他类,这样想。
A -> B -> C -> D
在该示例中,let -> 表示 B 继承自 A 等。
如果你这样想,类可以变成比它们少的类(向左):D 可以变成 C、B 或 A。对于 B,右侧的类是不可访问的,因为它们“更高” “在链条上,因此你不能把 B 变成 C 或 D。
在你的例子中,
员工 -> 经理
Managers can move left to Employee, so you can morph it that way, but Manager is to the RIGHT of Employee, which as said earlier, makes that transition impossible.
The reasoning is because, when you inherit, you gain all the benefits of the base class; variables, functions, all of it. When you try to go up the chain, you're adding variables, classes, etc, and you essentially have to re-create your object to do so, as it now takes more memory and will behave differently than originally. But, going down the tree, you're essentially just stripping an onion; taking off layers to reveal the spot of the onion you're after. They're all there to begin with, they're just not directly visible since they make up the smaller parts.