java - 父类(super class)中的私有(private)final可以被覆盖吗?

标签 java

Which three statements are true? (Choose three.)

A. A final method in class X can be abstract if and only if X is abstract.

B. A protected method in class X can be overridden by any subclass of X.

C. A private static method can be called only within other static methods in class X.

D. A non-static public final method in class X can be overridden in any subclass of X.

E. A public static method in class X can be called by a subclass of X without explicitly referencing the class X.

F. A method with the same signature as a private final method in class X can be implemented in a subclass of X.

G. A protected method in class X can be overridden by a subclass of X only if the subclass is in the same package as X.

这个问题来自 SCJP。答案是 BEF

我理解 BE,但 F 说该方法是“私有(private)最终”,那么子类如何覆盖该方法,因为它定义为最终和私有(private)方法。

请清除F点。

最佳答案

答案 F 不是覆盖的示例,而是方法范围的示例。在类中声明为 private 的方法对该类的子类不可见,因此不存在重叠;子类在父类(super class)中看不到它可以重写的方法。子类有自己的方法 void foo(int),完全不知道父类(super class)的 private void foo(int)

关于java - 父类(super class)中的私有(private)final可以被覆盖吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21922663/

相关文章:

Java 自省(introspection) - 奇怪的行为

java - 新的遗迹记录机制

java - jaxb:内联元素

java - 如何在 Java 中散列密码?

java - 无法将 jzmq.dll 加载到 java 中

java - Mockito - 是否有 "value not in List"的匹配器?

java - 如何创建带有半透明色 block 的透明 gif/png 图像?

java - 缺少 Android 网络连接状态。

java - 如果我使用 component-scan 并将 base-package 设为我的根包,Spring 是否会影响性能?

java - SSLException : Received fatal alert: certificate_unknow