The variables that are declared within an interface acts like final and static variables.
The advantage of interface is that as these are placed in the top level of class hierarchy, these are available for many subclasses.
Example:
access interface interface-name
{
return-type method-name(parameter-list);
“
“
}
Here the access may be either public or non-public(default). All the variables and methods that are declared within an interface are public if it is declared as public.
For the members of interface abstract keyword is optional.
Interfaces are to achieve multiple inheritance. Java classes doesn’t allow multiple inheritance but we can achieve it through Java interfaces indirectly. That is we can implement more number of interfaces to a class.
To inherit an interface to a class implements key word is used.
Interface A
{
public void getData(int x);
}
class B implements A
{int a;
public void getData(int x)
{
x=a;
}
}
If a class implements more than one interface the interfaces are separated with a comma.
Note:
1. The methods that implement an interface must be declared public.
2. The type signature of the implementation method must match with the type signature specified in the interface.
Like abstract classes we can not create object but we can refer subclass objects with the references.
An interface can also extend to another interface. One interface can be inherited to another interface by using the keyword extends. When a class implements the interface it must provide the implementations for all methods in the interface inheritance chain.

