简体   繁体   English

接口和抽象类

[英]Interfaces and abstract classes

Which is not true about interfaces and Abstract classes? 哪个接口和抽象类不正确? (at least mark two answers) (至少标记两个答案)

a. 一个。 Abstract class support to the inheritance relationship but not realization relationship. 抽象类支持继承关系但不实现关系。

b. Interface supports to the realization relationship but not inheritance relationship. 接口支持实现关系但不支持继承关系。

c. C。 Both Abstract class and Interface are supporting inheritance relationship. Abstract类和Interface都支持继承关系。

d. d。 All above statements are correct. 以上所有陈述都是正确的。

I am little bit confused about the answer can any one help me.My guess is a,b,d 我有点困惑,答案可以帮助我。我猜是a,b,d

The question you've been set is so badly worded it can't have any sensible correct answer without further definition. 你设置的问题是如此严厉,如果没有进一步的定义,它就没有任何合理的正确答案。 As others have pointed out, option (d) brings about logical inconsistencies. 正如其他人指出的那样,选项(d)带来了逻辑上的不一致。 Putting that aside though, the question remains ambiguous at best. 尽管如此,这个问题充其量只是含糊不清。

Inheritance and Realisation are binary relationships. 继承和实现是二元关系。 There's no single answer therefore to whether Abstract Classes or Interfaces 'support' them. 因此,抽象类或接口是否支持它们没有单一的答案。 Instead, you have to ask: what roles in each relationship (Inheritance, Realisation) can each each classifier (Abstract Class, Interface) play? 相反,你必须要问:每个关系(继承,实现)中的每个分类器(抽象类,接口)可以扮演什么角色? For the sake of simplicity, let's call the roles "parent" and "child" in both cases. 为简单起见,我们在两种情况下都将角色称为“父”和“子”。 Not semantically correct, but good enough for our purposes. 在语义上不正确,但对我们的目的来说足够好。 For the avoidance of doubt though: 尽管如此,为避免疑惑:

  • For inheritance: "parent" means the classifier inherited from, "child" means the inheriting classifier 对于继承:“parent”表示继承自的分类器,“child”表示继承分类器
  • For Realisation: "parent" means the classifier defining the specification, "child" means the classifier providing the realisation. 对于实现:“父”表示定义规范的分类器,“子”表示提供实现的分类器。

Finally, we need to define what "inheritance" and "realisation" mean. 最后,我们需要定义“继承”和“实现”的含义。 Since you've tagged this as java, we can assume "inheritance" means "extends" and "realisation" means "implements". 由于您已将其标记为java,因此我们可以假设“继承”表示“扩展”,“实现”表示“实现”。 However, that's a really questionable definition for Inheritance - which normally means implementation inheritance. 但是,这对于继承来说是一个非常值得怀疑的定义 - 通常意味着实现继承。 Not the same semantics as Java's "extends". 与Java的“扩展”不同的语义。

OK. 好。 So now we can define a truth table for which roles each classifier can play. 所以现在我们可以定义一个真值表,每个分类器可以扮演哪些角色。

               |  Inheritance  |   Realisation  |
               |parent | child | parent | child |
---------------|-------|-------|--------|-------| 
Abstract Class |   T   |   T   |    F   |   T   |
Interface      |   T   |   T   |    T   |   F   |
-------------------------------------------------

From that, we can see: 从那以后,我们可以看到:

  1. Abstract Classes support both roles in the Inheritance relationship. Abstract Classes支持继承关系中的两个角色。
  2. Abstract Classes support only one role in Realisation relationship. Abstract Classes在Realization关系中仅支持一个角色。

Note also that the table would be different if "inheritance" means "implementation inheritance" rather than "extends". 另请注意,如果“继承”表示“实现继承”而不是“扩展”,则表格会有所不同。

Let's now look at the options in your question 现在让我们看看你问题中的选项

a. 一个。 Abstract class support to the inheritance relationship but not realization relationship. 抽象类支持继承关系但不实现关系。

We can't say if that's true or false without defining what "support" means. 如果没有定义“支持”的含义,我们不能说这是真还是假。 Abstract classes support both Inheritance roles, so we can state the first clause is true. 抽象类同时支持继承角色,因此我们可以声明第一个子句为true。 However they only support one Realisation role. 但是它们只支持一个Realization角色。 So does that mean they do or don't support it? 这是否意味着他们支持或不支持它? There's no answer unless "support" is explicitly defined as either "fully support" - both roles - or "partial support" - at least one role. 除非“支持”明确定义为“完全支持” - 两种角色 - 或“部分支持” - 至少一个角色,否则没有答案。

There's similar ambiguity for option (b) in your list. 您的列表中的选项(b)也存在类似的歧义。

Option (c) is however decidable. 然而,选项(c)是可判定的。 Interfaces and Abstract Classes both support both Inheritance roles therefore (c) is true. 接口和抽象类都支持继承角色,因此(c)是正确的。 Note that if "inheritance" means "implementation inheritance" rather than "extends" however, then (c) is false. 注意,如果“继承”意味着“实现继承”而不是“扩展”,那么(c)是错误的。

In conclusion: without proper definition of the problem it's not possible to answer. 总之:如果没有正确定义问题,就无法回答。

hth. 心连心。

oh memories... is this for the java certified programmer? 哦,回忆......这是java认证的程序员吗?

a. 一个。 true 真正
b. false
c. C。 true 真正
d. d。 wtf is correct? wtf是对的吗? true or false? 对或错? I think its... false 我认为它......错误

and you have to negate the answser... 你必须否定答案...
check this out for more information about abstract classes and interfaces 有关抽象类接口的更多信息,请查看此内容

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

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