gpt4 book ai didi

java - 为接口(interface)方法指定抽象或不指定有什么区别?

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:42:18 24 4
gpt4 key购买 nike

在 Java 接口(interface)的方法上指定 abstract 关键字和不指定有什么区别?

喜欢:

public void foo();
public abstract void foo();

最佳答案

没有区别。查看 JLS Interfaces - Abstract Method Declatations :

Every method declaration in the body of an interface is implicitly abstract, so its body is always represented by a semicolon, not a block.

另请注意:

For compatibility with older versions of the Java platform, it is permitted but discouraged, as a matter of style, to redundantly specify the abstract modifier for methods declared in interfaces.

关于java - 为接口(interface)方法指定抽象或不指定有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6725357/

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