Stanko
Stanko

Reputation: 4465

Overriding default interface method with abstract method

I find it weird and was wondering if it is something that is regularly used. When can it be useful?

public interface InterA { 
   Object getInfo() throws Exception1; 
}
public interface InterB {
   public default Integer getInfo(Object s) {return 67;} 
}

public interface InterC extends InterA, InterB {
   @Override public abstract Integer getInfo(Object s);
}

Upvotes: 7

Views: 1146

Answers (2)

ZhongYu
ZhongYu

Reputation: 19682

This exists before default interface methods. For example, an abstract class can make

    @Override
    abstract public int hashCode();

forcing subclasses to provide implementations for hashCode, possibly because of additional requirements imposed by the abstract class.

Upvotes: 3

Suresh Atta
Suresh Atta

Reputation: 121998

Of course you are allowed to do that. The name itself telling that it's abstract. You are allowed to do that where as the implemented class of that abstract class must override that method.

When you decide to be an abstract, you need not to implement.

Upvotes: 1

Related Questions