Why declare an interface as abstract?

前端 未结 11 808
予麋鹿
予麋鹿 2020-12-13 03:36

What\'s point of declaring an interface as abstract? Same thing for an interface method. Is there a point to it?

eg.

public abstract interface Presen         


        
相关标签:
11条回答
  • 2020-12-13 04:08

    Makes no difference - interfaces and interface methods are always abstract but you don't have to add the modifier (and interface methods are always public so you don't need the public modifier too).

    From the JLS:

    9.1.1.1 abstract Interfaces

    Every interface is implicitly abstract. This modifier is obsolete and should not be used in new programs.

    0 讨论(0)
  • 2020-12-13 04:10

    Typically, you don't declare the interface, or its methods, as abstract. They are implicitly.

    The methods are also public, so you can skip that also. :-)

    0 讨论(0)
  • 2020-12-13 04:10

    I think just verboseness, explicitness and consistency with the class syntax and semantics...

    You don't have to, but maybe it could help if some reader of your code is distracted or not very versed in Java.

    0 讨论(0)
  • 2020-12-13 04:15

    There is no point of declaring interface to be abstract. As the methods in the interface are abstract only.. One more thing abstract class can have both concrete and abstract methods but in the interface there should be only abstract methods.

    0 讨论(0)
  • 2020-12-13 04:19

    Question: Can we declare an Interface with “abstract” keyword? Answer: Yes, we can declare an interface with “abstract” keyword. But, there is no need to write like that. All interfaces in java are abstract by default. Same applies to interface methods

    Please go throw this link https://javaconceptoftheday.com/java-interview-questions-on-interfaces/

    INTERFACE CAN HAVE STATIC METHOD SINCE JAVA8

    0 讨论(0)
  • 2020-12-13 04:21

    Interfaces and interface methods are implicitly abstract even if not declared as so. So there is no need to explicitly specify it.

    0 讨论(0)
提交回复
热议问题