what is use of interface in java code example
Example 1: Interface in java
interface Vehicle
{
public void accelerate();
}
class BMW implements Vehicle
{
public void accelerate()
{
System.out.println("BMW accelerating...");
}
}
public class InterfaceDemo
{
public static void main(String[] args)
{
BMW obj = new BMW();
obj.accelerate();
}
}
Example 2: functional interface java
A functional interface is an interface that contains only one abstract method. They can have only one functionality to exhibit.