Krivalar Tutorials 
Krivalar Tutorials

Java Interfaces


<Class

Package >





An interface is a type definition which has only method declarations and fields. From Java 8, Interfaces could also have default methods

Java Interface - Example


interface Shape {
float Pi=3.14f;
float calculateArea();
}

interface Vehicle{
void turnSteeringWheel();
void applyBrake();
void accelerate();
void rightIndicator();
void leftIndicator();
void pressHorn();
void trunHeadlights();
void onWiper();
}

Java Interface - static and default methods


interface Shape {
static void sayHi(){
	System.out.println("Hi");
}
default void sayWelcome(){
	System.out.println("Welcome");
}
}

Java Interface & Class


<Class

Package >