开发者

Do we need to declare interface methods as abstract [duplicate]

开发者 https://www.devze.com 2023-04-01 06:45 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: Java abstract interface
This question already has answers here: Closed 11 years ago.

Possible Duplicate:

Java abstract interface

public interface Foo {
   abstract public void bar();
}

I guess we don't need to declare abstract as well as public i开发者_StackOverflow社区n the above interface. Will the compiler catch this is as a warning or is it allowed by the compiler.


In an interface the the modifiers public and abstract are implied for methods, similarly for fields public static and final are implied. For inner classes static is implied.


It is allowed. public and abstract are automatically added to every interface method.


You don't have to, every interface method is implicitly abstract. It will not be a mistake to write it though.


For interface methods, it is not necessary to declare public and abstract by default those are public and abstract


It is not necessary but it won't hurt to write it. These modifiers are implied.

I like to do it so everything is explicit and may help other programmers that will work with your code.


You are allowed to declare abstract inside the interface. The complier can pass it.

public interface foointerface {

    abstract public void foo();

    public void bar();
}

But there is no point to declare in abstract since we would not implement or allow to implement methods inside interface.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号