What modifiers allowed for methods in Interface

What modifiers allowed for methods in Interface

Answer: Only public & abstract modifiers are permitted.

All methods and fields in an interface should be declared in such a way so that they can be invoked from anywhere. Not only from within a subclass. Only public modifier can make this happen. By default all method in the java interface are abstract means we can not provide body of the method and without body method does not make any sense until another class implements it and provide full implementation of it.

One more thing: We should avoid to have a field in interface. if possible.

An interface simply defines an external API without providing any implementation. The whole idea behind an interface is that the implementation is left entirely to the implementing class.

Leave a Reply

Your email address will not be published. Required fields are marked *

I am not Robot *