0 votes
in JAVA by (6.0k points)
What is the interface? Why you use it if you cannot write anything concrete on it?

1 Answer

0 votes
by (30.8k points)

The interface is used to define API. It tells about the contract your classes will follow. It also supports abstraction because a client can use interface method to leverage multiple implementations e.g. by using List interface you can take advantage of random access of ArrayList as well as flexible insertion and deletion of LinkedList. The interface doesn't allow you to write code to keep things abstract but from Java 8 you can declare static and default methods inside interface which are concrete.

Related questions