Modal Box

Interface in java

Interface in java is an alternative to achieve multiple inheritance
similarly, as abstract class interface may not be instanciated.

   In java code is written either in class or in interface
⇒ Interface may be declared with the help of interface keyword and is implemented                                          by using implements keyword .
⇒ A class may implements multiple interfaces and implementing class must override abstract methods.

Example of implementation of interface in java

interface Animal
{
  void voice();
}

class Dog implements Animal { public void voice() { System.out.print("Bho Bho"); } }
class CheckMain { public static void main(String args[]) { Dog d1= new Dog(); d1.voice(); } }

Interface may be extended as following :

interface Animal{ 
 void voice(); 
} 
interface WildAnimal extends Animal{ 
 void speed(); 
}

class tiger implements WildAnimal { public void voice() { System.out.println("Gurr Gurr"); } public void speed() { System.out.println("70 km/hour"); } }
class CheckMain { public static void main(String args[]) { tiger t1=new tiger(); t1.voice(); t1.speed(); } }

Video/ C Introduction

Watch video in full size
Wordpress Social Share Plugin powered by Ultimatelysocial