JAVA Interface Implementation
This is how a class implements an interface. It has to provide the body of all the methods that are declared in interface. Interface is like a class but not exactly a class.
Note: Class implements interface but an interface extends another interface.
Example:
interface MyInterface
{
public void method1();
public void method2();
}
class XYZ implements MyInterface
{
public void method1()
{
System . out .println("implementation of method1");
}
public void method2()
{
System . out .println("implementation of method2");
}
public static void main(String arg[])
{
MyInterface obj = new XYZ();
obj.method1();
}
}
Output:
implementation of method1