Friday 3 February 2017

Interface in JAVA 8(JDK 1.8 version)

It is possible to define method inside the interface by implementing default method or static method in JAVA 8.

Example1: using default method:

package test;
interface A{
default void show()
{
     System.out.println("java");
}
}
class B implements A
{
    

}

class InterfaceExample1
{
     public static void main(String[] args)
     {
          B obj=new B();
          obj.show();
     }
}
Output

java

Example2: Using static method:
package test;
interface A{
static void show()
{
    System.out.println("java");
}
}

class InterfaceExample2
{
    public static void main(String[] args)
    {
        A.show();
    }
}
Output
java

No comments:

Post a Comment