gpt4 book ai didi

java - java doc中关于抽象与接口(interface)的令人困惑的解释

转载 作者:行者123 更新时间:2023-12-02 10:47:56 26 4
gpt4 key购买 nike

在java文档中,这样说:

Unlike interfaces, abstract classes can contain fields that are not static and final, and they can contain implemented methods.

这是正确的文字吗?这个not部分让我感到困惑,因为接口(interface)没有staticfinal字段,对吗?

来源:http://download.oracle.com/javase/tutorial/java/IandI/abstract.html

谢谢。

编辑:

public interface GroupedInterface extends Interface1,
Interface2, Interface3 {

// constant declarations
double E = 2.718282; // base of natural logarithms

// method signatures
void doSomething (int i, double x);
int doSomethingElse(String s);

}

An interface can contain constant declarations in addition to method declarations. All constant values defined in an interface are implicitly public, static, and final. Once again, these modifiers can be omitted.

最佳答案

Every field declaration in the body of an interface is implicitly public, static, and final. It is permitted to redundantly specify any or all of these modifiers for such fields.

来自 Java 语言规范 ( here ) 的第 9.3 节

关于java - java doc中关于抽象与接口(interface)的令人困惑的解释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4380817/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com