覆盖超类的实例变量 [英] Overriding a super class's instance variables

查看:88
本文介绍了覆盖超类的实例变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我们无法覆盖子类中超类的实例变量?

Why are we not able to override an instance variable of a super class in a subclass?

推荐答案

因为如果你改变了数据成员的实现,很可能会破坏超类(想象一下,改变超类的数据成员)一个浮点到一个字符串)。

Because if you changed the implementation of a data member it would quite possibly break the superclass (imagine changing a superclass's data member from a float to a String).

这篇关于覆盖超类的实例变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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