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();
}
interface Demo
{
int x=10; -> the signature is public static final int x=10;
void show(); -> abstract void show();
void disp();-> abstract void disp();
}
interface InterfaceName1
{
..
..
}
interface InterfaceName2
{
..
..
}
..
..
..
class classname implements InterfaceName1,InterfaceName2,...
{
..
..
}
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();
}
}