Java Interface

Java Interface Definition - 

It is fully unimplemented class used for declaring a set of operations of an object. It contain only public static final variables and public abstract methods. It is created by using the keyword interface

It is always created as a root class in object creation process. We must design an object starts with interface if its operations have different implementations. 

So interface tell what should implement but not how.

Example - 

Vehicle, Animal objects creation must be started with interface. These object operation have different implementation based on different type of vehicle like Bus, Bike, Car etc... 

and different types of animals like Lion, Tiger, Elephant, Rabbit, Dog etc...

//Vehicle.java

interface Vehicle {
         public void engine();
         public void breaks();
}

Multiple Inheritance in Java Example

java interface
Multiple Inheritance
interface A {  
void print();  
}  

interface B {  
void show();  
}  

class Test implements A,B{  
public void print(){System.out.println("Welcome");}  
public void show(){System.out.println("To JavaTechWorld");}  
  
public static void main(String args[]){  
Test obj = new Test();  
obj.print();  
obj.show();  
 }  
}  

Leave a Comment

%d bloggers like this: