Home > DeveloperSection > Articles > Interface in Java

Interface in Java

Java Java  J2EE 
0 Comment(s)
 1801  View(s)
Rate this:

Interface in Java   

Interface are used to achieving fully Abstraction in java. If you want to achieve multi-threading in java then interface is an only way for that. By default, interface fields are public, static and final and methods are public and abstract. You can only defined abstract method in interface not giving the body of method. You are not create instance of interface same as abstract class.

If you want to implements more than one interface that are possible by using extends keyword in java. if you are not adding keyword public abstract before methods and public static final before fields then i.e. also compiled successfully. after compilation compiler will be adding itself.

The syntax of the Interface is as follow:

interface MyInterface {
public abstract void displayName ();

For Example,

interface MyInterface
       void DisplayName();  
interface MyInterface2 extends MyInterface // extend another interface
       void DisplayAdd();  
class TestingInterface implements MyInterface2
public void DisplayName()
       System.out.println("Anupam Mishra");
public void DisplayAdd()
public static void main(String args[])
       TestingInterface obj = new TestingInterface();  //instantiate object of the class


Anupam Mishra




Don't want to miss updates? Please click the below button!

Follow MindStick