Interface in Java

Interface in Java

Interface in Java is one of the important concepts what all software professionals and all computer science students should be strong enough to code in. Interface in Java is also an important question asked in majority of the interviews and in exams as well. Since guys find hard and quiet confusing in this concept of object oriented programming studies, I described the easiest way on the exact concept with examples in this page. Let me share my knowledge on this with you.

The main difference between Interface and Abstract Class in Java is methods of a Java interface are implicitly abstract. Interface don’t have any implementations. Interface contain only the signature alone without body implementation. The body implementation part is done in the class in which it is implemented. A class which is implementing an interface has to implement all the methods of the interface. Interface is not a class. Interface is an entity. Interface forms the contract between the class and the outside world. Interface should be implemented in another class using the keyword implements. Interface cannot be instantiated, but we can instantiate a class that implements the interface. Java does not support multiple inheritances. So the concept of multiple inheritances can be achieved by using interface in java. Also many interface can be implemented in a class using the keyword implements with the interface names separated with commas. It is also illustrated with an example in this page.


Interface in Java

interface insurance
{
public void account ();
}

class bank implements insurance
{
public void account ()
{
System.out.println ("It’s easy to create a bank account");
}
}

public class banking
{
public static void main (String [] args)
{
insurance trading=new bank ();
trading.account ();
}
}

For multiple interface in java please visit the below link.


Thanks...

No comments:

Post a Comment

My Profile