what is a abstract method on a interface in java

28,193

Solution 1

abstract is redundant in this case. All methods defined on an interface are public and abstract by definition.

Excerpt Java Language Specification section 9.4

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

Every method declaration in the body of an interface is implicitly public.

Solution 2

Both public and abstract modifiers are implicit in interfaces and should be avoided.

Solution 3

A method in an interface is public and abstract by definition. I have heard some people say they feel that explicitly declaring them like that makes it clearer, but to me it seems like extra noise.

Solution 4

As per this document all the methods of interface is public and abstract, so there is no mean to define explicitly abstract method inside the interface.

Share:
28,193
Marthin
Author by

Marthin

Another programming nerd.

Updated on July 26, 2022

Comments

  • Marthin
    Marthin almost 2 years

    Possible Duplicate:
    Why would one declare a Java interface method as abstract?

    I found the following code in one of our ejb interfaces. Does anyone know what the abstract does in the interface? If you do please also explain why it might be needed or provide a reference to read about it =)

    @Local
    public interface IDomasOrderProcessor {
    
        public abstract void executeOrderLines(List<OrderLine> lines);
        public abstract void setupJob(List<OrderLine> lines);
        public abstract void setupJob(OrderLine line);
    }