抽象方法实现与抽象方法覆盖.这两个抽象类的意思相同吗? [英] Abstract Method Implementation vs Abstract Method Overriding. Do these two mean the same for Abstract Classes?

查看:140
本文介绍了抽象方法实现与抽象方法覆盖.这两个抽象类的意思相同吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我几乎要参加 Java SE 8程序员I 考试( 1Z0-808 ).我正在使用此学习指南: https://www .selikoff.net/java-oca-8-programmer-i-study-guide/.在回答第5章(类设计)中的复习问题时,我在以下问题上失败了:

I'm almost taking the Java SE 8 Programmer I exam (1Z0-808). I'm using this study guide: https://www.selikoff.net/java-oca-8-programmer-i-study-guide/. When answering the review questions in chapter 5 (Class Design) i failed at this question:

关于具体的子类,以下哪项是正确的? (选择所有适用项)

  1. 一个具体的子类可以声明为抽象的.
  2. 一个具体的子类必须实现所有继承的抽象方法.
  3. 一个具体的子类必须实现在 继承的接口.
  4. 一个具体的子类不能标记为final.
  5. 抽象方法不能被具体的子类覆盖.
  1. A concrete subclass can be declared as abstract.
  2. A concrete subclass must implement all inherited abstract methods.
  3. A concrete subclass must implement all methods defined in an inherited interface.
  4. A concrete subclass cannot be marked as final.
  5. Abstract methods cannot be overridden by a concrete subclass.

我的回答是2和5.但是只有第二个是正确的.我选择了第五个答案,因为我认为您不能覆盖抽象类中的抽象方法,但是您可以实现它,例如inferfaces,它几乎像Java 8以来的抽象类.

My answers were 2 and 5. But only the 2nd was correct. I selected the 5th answer because i thought that it is true you cannot override an abstract method from an abstract class, but you can implement it, like inferfaces, which are almost like abstract classes since Java 8.

在谈论抽象类时,知道接口的抽象方法是实现的,而不是被覆盖的:说抽象方法可以由具体的子类覆盖"而不是抽象方法可以由具体的子类实现"是正确的吗?

Knowing that interfaces abstract methods are implemented, not overriden, when talking about abstract classes: is it correct to say "Abstract methods can be overriden by a concrete subclass" instead of "Abstract methods can be implemented by a concrete subclass"?

如果我们注意第二个答案(是正确的答案),他们会使用实施"一词.

If we pay attention to the second answer (which is the right one) they used the word "implement".

推荐答案

如果非abstract方法mC覆盖类C中的抽象方法mA,则将mC表示为实现 mAC

If a non-abstract method mC overrides an abstract method mA from a class C, then mC is said to implement mA from C.

在类C中声明或由类C继承的实例方法mC,从C覆盖 ,在接口I中声明的另一方法mI,前提是以下所有条件均是正确:[...]

An instance method mC declared in or inherited by class C, overrides from C another method mI declared in an interface I, iff all of the following are true: [...]

请注意,在覆盖接口方法时,它确实使用了术语覆盖" .

Note that it does use the term "overrides" in reference to overriding interface methods.

更简单地说,如果方法覆盖了抽象方法(从抽象类或接口),则覆盖方法实现.不过,它仍然被视为替代.

In more plain terms, if a method overrides an abstract method (either from an abstract class or interface), then the overriding method implements the abstract method. It's still considered an override, though.

abstract class A {
    abstract void m();
    void n() {}
}
class C extends A {
    // C.m() both overrides and implements A.m()
    @Override
    void m() {}
    // C.n() overrides A.n(), but does not implement it
    @Override
    void n() {}
}

这篇关于抽象方法实现与抽象方法覆盖.这两个抽象类的意思相同吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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