Java语言中的继承 [英] Inheritance in Java language

查看:129
本文介绍了Java语言中的继承的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们说java遵循单个继承模型,即Java类最多只能扩展一个类。然后说每个java类都继承自Object类。

We say that java follows a single inheritance model i.e. a Java class can extend only one class at max. and then say that every java class is inherited from Object class.

假设有两个类A和B.A和B都从Object扩展。现在假设A扩展B.是否意味着A具有多重继承(A是从B和类对象继承)?

Suppose there are two classes A and B. Both A and B extend from Object. Now suppose A extends B. Doesn't it imply that A has multiple inheritence (A is inheriting from both B and Class Object)?

推荐答案

看看传递继承之间的区别(C直接从B继承并从A传递):

Look at the difference between transitive inheritance (C inherits directly from B and transitively from A):

和多重继承(C继承自A和B):

and multiple inheritance (C inheriting from both A and B):

除了被覆盖的具有相同签名的方法之外,所有内容都被添加。甚至添加了使用相同名称声明的变量,它们只是被称为隐藏但仍然可以使用强制转换来访问,如果它是直接父级,则可以访问它。

Everything is just added on, except methods with the same signature, which are overridden. Even variables declared with the same name are added on, they're just said to be "hidden" but can still be accessed using casting, or the super keyword if it's the immediate parent.

这篇关于Java语言中的继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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