Java继承 - 实例变量重写 [英] Java Inheritance - instance variables overriding

查看:270
本文介绍了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继承 - 实例变量重写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆