Hii frnds, here we will know an exciting feature of
JAVA 9, that is definition of private method in interface. That means it is
possible that we can happily define a private method inside the interface.
IntefaceExample.java
interface Test
{
void show();
default void print()
{
System.out.println("JAVA means SILAN TECHNOLOGY");
display();
}
private void display()
{
System.out.println("www.java8s.com");
}
}
class Demo implements Test
{
public void show()
{
System.out.println("SILAN TECHNOLOGY");
}
}
class InterfaceExample
{
public static void main(String[] args)
{
Demo obj=new Demo();
obj.show();
obj.print();
}
}
Output
SILAN TECHNOLOGY
JAVA means SILAN TECHNOLOGY
www.java8s.com