java interface syntax for multiple inheritance w3sch 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: Interface in java

// interface syntax
interface InterfaceName
{
   fields // by default interface fields are public, static final
   methods // by default interface methods are abstract, public
}

Tags:

Java Example