本文介绍了Java 继承 - 实例变量覆盖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么在继承中没有覆盖超类的实例变量?
Why are Instance variables of a superclass not overidden in Inheritance ?
推荐答案
因为继承旨在修改行为.行为通过方法公开,这就是它们可以被覆盖的原因.
Because inheritance is intended to modify behaviour. Behaviour is exposed through methods, and that's why they can be overridden.
字段不是行为而是状态.您不需要修改它,也不需要修改超类使用的私有方法.它们旨在让超类完成它的工作.
Fields are not behaviour but state. You don't need to modify that, nor the private methods employed by the superclass. They are intended to allow the superclass to do it's job.
这篇关于Java 继承 - 实例变量覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!