What is an interface and how will you go about implementing an interface?
Interface is a set of protocols which are used to define the structure of an application. They support multiple interface inheritance. An interface can contain variable. These variables by default are public static final. Interfaces are by default abstract. An interface can contain only abstract methods. Interfaces are implemented in class by using the implements keyword. In interfaces the methods or functions are declared only, they are defined in the class.
For exampleInterface a
{
Int n1=5;
Void s();
Void s1();
}
//full implementation of the interface
class b implements a
{
public void s()
{
System.out.println(“Hello s”);
}
public void s1()
{
System.out.println(“Hello s1”);
}
public static void main(String args[])
{
System.out.println(n1);
int c=n1*n1;
System.out.println(c);
b obj= new b();
obj.s();
obj.s1();
}
}