简体   繁体   English

2个班级之间有什么关系?

[英]what is the relationship between 2 classes?

If i have Class A and Class B what is the relation-ship between them if nothing else is stated (no HAS-A) relation-ship stated, is it Association? 如果我有A类和B类,如果没有其他说明(没有HAS-A),则它们之间的关系是什么,是协会吗?

class A{}
class B{}

There is no relation between those classes. 这些类之间没有关系。

The only relationship that I can see is that they both implicitly inherit from Object . 我可以看到的唯一关系是它们都隐式继承自Object

它们是称为java.lang.Object的父类的子类,除此之外,没有可见的关系。

Based on the information you supplied. 根据您提供的信息。 No, there is no relationship. 不,没有关系。 In java, both inherit from the java.lang.Object. 在java中,两者都继承自java.lang.Object。 But from OO perspective, there is no relationship. 但是从面向对象的角度来看,没有关系。

Class can be related in the following ways: 类可以通过以下方式关联:

Aggregation - This is a has-a relationship where Class A has at least 1 field whose type is of classB Inheritance - This is an is-a relationship where a class B is a specialization of another class A. In this kind of relationship, the classB inherits all the behaviours of the class A. 聚合-这是一个具有关系的关系,其中类A具有至少一个类型为classB的字段。继承-这是一种具有关系的关系,其中类B是另一种类A的特化。 classB继承了类A的所有行为。

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

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