Opening Hours :7AM to 9PM
Interface is similar to class.It is used to achieve the multiple inheritance in java language.
Interface is replacement of abstract class.
Syntax:
interface InterfaceName
{
list of public static final variables;
list of abstract methods();
}
Every interface can be identify with interface keyword and represented by user defined name.
interface Addition
{
void add();
}
interface Substraction
{
void sub();
}
class Demo implements Addition,Substraction
{
int x,y,z;
public void add()
{
x=100;
y=200;
z=x+y;
System.out.println(z);
}
public void sub()
{
x=100;
y=200;
z=x-y;
System.out.println(z);
}
void mul()
{
x=100;
y=200;
z=x*y;
System.out.println(z);
}
}
class Main
{
public static void main(String args[])
{
Demo d=new Demo();
d.add();
d.sub();
d.mul();
}
}