Interface In Java 8s

Java 8(JDK 1.8 version) introduces a new concept of default method and static method implementation in interface. We can define method inside interface using the keyword default and static.

Java interface default method

To define a default method in java interface, we use “default” keyword with the method signature.

For example,

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

}

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

Output

Silan Technology
 

Java interface static method

Example:

package test;
interface I{
static void show()
{
System.out.println("Silan Technology");
}
}

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

Output

Silan Technology

Our Services:

Java Training | Python Training | Machine Learning with Python Training | Deep Learning with Python Training | Data Science with Python Training | Projects

Silansoftware Pvt.Ltd, BBSR
Call to: 0674-2361252

Comment