-First some OO theory:
In OO paradigm in general, the interface or the public interface is constituted by the methods an object has.
The interface answer to the question: what operations may be performed by this object?
That's why is often explained as the "contract".
Object "a" of class "Xyz" should do:
// one operation that doesn't return anything
-oneOperation():void
// other operation that return boolean
-otherOperation():bool
// another that receives two string and return a String
-anotherOperation( a: String, b String ): String
etc. etc.
It may additionally perform other operations inside the class, private operations, that's the object private interface, we don't care too much about that because, well, we can't use it since it's private ( we do care if we are modifying the class source code, but's that's another topic)
That's about OO theory very high level.
-Implementations
In programming languages such as Java and C# which are statically typed the operations of an object are defined by the type that object belongs to AT COMPILE TIME ( this is important )
For instance, in Java the object
"Oscar"
Has a method
// Returns the character at specified index
-charAt( index: int ) : char
We know this, because that objects is of type String and the public interface of String defines the charAt method.
So, the compilers check that a method named "charAt" does exists in that object ( and help you with typing mistakes such as chatAt )
-So, back to your question
So, after all this explanation and returning to your original question:
but what is the need of it?
When you're defining a system using OO technology and specifically using an statically typed programming language such as Java and C# you define the operations your object will respond.
As we see before, that will be implicity defined by the type of the object; the class that is. But, ¿what happens, when you need that two objects from different class hierarchies respond to the same operation?
What C++ did, was to allow multiple inheritance, an object may inherit the public interface of two different classes, such as "Bird" and "Horse" creating a "Pegasus" class.
The problem with inheritance is that's the worst form of high-coupling which is not desirable ( nor avoidable though ) and C++ multiple inheritance presented some additional problems it self.
So when Java was designed ( and C# in consequence, since this was a good feature ) they forbid multiple inheritance and as a workaround they introduced the interface keyword, to allow you to work on the situation when you need two classes from different type hierarchy respond to the same method.
In both, the way the interface will work, is only to define what operations the object will respond to ( exactly as the OO concept ) and thus all of them should be public.
When a class is said to implement and interface, it commits to have those methods available.
A very easy to understand usage of and interface is Comparable which allows to the implementers to compare against another object.
For instance it may be simple to decide which object should go first when sorting a collections of numbers, 1 will be lower than 10,
But, if you have a collection of employees? Which should go first?, bye age?, by role? by name? This should be defined by the need of the system
Yet, you can create a data structure to hold for multiple kinds of objects granted that all of them respond to the :
-compareTo(o: T ): int
method.
And of course not all of them should inherit the same class.
I hope this helps.