简体   繁体   English

子类是否继承超类的关联类

[英]Do sub classes inherit the associated classes of super class

I just want to clear a concept of inheritance. 我只想清除继承的概念。 Do sub classes inherit the associated classes of super class. 子类是否继承超类的关联类。 To make my question clear let suppose an example Assume there is a super class Person, having association relationship with BloodGroup class and Address class, and Women and Men as its sub classes, now tell me whether the Sub Classes will inherit these two associated classes from parent class or not? 为了使我的问题更清楚,让我们以一个示例为例:假设有一个超类Person,与BloodGroup类和Address类具有关联关系,而Women和Men作为其子类,现在告诉我,这些子类是否将从以下两个类中继承家长班吗?

是的,如果它们是publicprotected

子类继承其父类的除私有字段之外的所有字段。

A subclass will only inherit the structure (methods and properties) of it's superclass and it's superclass's superclasse's. 子类将仅继承其超类及其超类的结构(方法和属性)。

If by associated classes you mean import. 如果通过关联的类,则表示导入。 The subclass does not inherit the super's imports. 子类不继承父级的导入。 Imports are file specific and used for compilation of individual .java files. 导入是特定于文件的,并且用于编译单个.java文件。

ie

Object
 -Person extends Object
    -Male extends Person

Male can use and override the methods and properties of both Person and Object as long as the access modifiers(public/protected/private/package) allow it. 只要访问修饰符(公共/受保护/私有/程序包)允许,Male可以使用和覆盖Person和Object的方法和属性。 Male does not care what objects are used in the methods or what code is run in them, it only uses them based on it's signature(returnType methodName(Parameters)). Male不在乎方法中使用了哪些对象或在其中运行了什么代码,它仅根据其签名使用它们(returnType methodName(Parameters))。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM