It is possible to define method inside the interface by implementing default method or static method in JAVA 8.
Example1: using default method:
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