A reference variable of a superclass can be assigned a reference to any subclass derived from that superclass. You will find this aspect of inheritance quite useful in a variety of situations.
And it is important to understand that it is the type of the reference variable --- not the type of the object that it refers to----that determines what members can be accessed. That is, when a reference to a subclass object is assigned to a superclass reference variable, you will have access only to those parts of the object defined by the superclass.
本文探讨了面向对象编程中继承的概念,特别是超类引用变量可以指向任何从该超类派生的子类实例这一特性。文章强调了这种设计灵活性的重要性和应用场景,并指出访问子类对象的成员时,实际上是通过超类引用变量的类型来决定可以访问哪些成员。
1328

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



