interface variable in java code example
Example 1: Interface in java
// interface in java example
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: java define interface
/* File name : Animal.java */
interface Animal {
public void eat();
public void travel();
}