---
title: "Interface in Java"  
description: "The interface is a mechanism to achieve fully abstraction. There can be only abstract methods in interface, not method body. An Interface is also used"  
author: "Anupam Mishra"  
published: 2015-12-11  
updated: 2018-03-27  
canonical: https://www.mindstick.com/articles/11947/interface-in-java  
category: "java"  
tags: ["java", "j2ee"]  
reading_time: 2 minutes  

---

# Interface in Java

**[Interface](https://www.mindstick.com/articles/12036/interface-in-c-sharp) are used to achieving** fully [Abstraction](https://www.mindstick.com/articles/944/abstraction-in-c-sharp) in java. If you want to achieve multi-[threading](https://www.mindstick.com/blog/784/multithreading-with-c-sharp) in java then interface is an only way for that. By default, interface fields are public, static and final and [methods](https://www.mindstick.com/articles/13060/runny-nose-remedy-methods-that-work-best) are public and abstract. You can only defined [abstract method](https://www.mindstick.com/articles/23305/abstract-methods-and-class-in-c-sharp) in interface not giving the body of method. You are not create [instance](https://www.mindstick.com/forum/155658/testing-connection-to-cloud-sql-instance-with-a-mysql-client-from-vm-instance) of interface same as abstract class.

If you want to implements more than one interface that are possible by using extends [keyword](https://yourviews.mindstick.com/view/87345/explained-the-importance-of-keyword-traffic) 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](https://www.mindstick.com/interview/358/which-is-the-first-level-of-compilation-in-the-dot-net-languages) [compiler](https://www.mindstick.com/articles/27/just-in-time-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()
{
           System.out.println("Allahabad");
}
public static void main(String args[])
{
       TestingInterface obj = new TestingInterface();  //instantiate object of the class
       obj.DisplayName();
       obj.DisplayAdd();
 }
 }  
```

**Output:**

**Anupam Mishra**

**Allahabad**

>

\

---

Original Source: https://www.mindstick.com/articles/11947/interface-in-java

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
