---
title: "Interface in java"  
description: "Interfaces An interface is a reference type in java and similar to a class. With in the interface we cannot write any implementation because it has t"  
author: "Anonymous User"  
published: 2018-09-06  
updated: 2018-09-06  
canonical: https://www.mindstick.com/blog/11960/interface-in-java  
category: "java"  
tags: ["java"]  
reading_time: 2 minutes  

---

# Interface in java

## [Interfaces](https://www.mindstick.com/articles/12100/interfaces-in-java-real-life-example)

An interface is a [reference type](https://www.mindstick.com/interview/235/what-is-difference-between-value-types-and-reference-types-in-vb-dot-net-or-c-sharp-value-types-vs-reference-types) in java and similar to a class. With in the interface we cannot write any [implementation](https://www.mindstick.com/forum/33764/how-to-implementation-of-class-in-c-sharp) because it has to highlight just the set of [services](https://www.mindstick.com/articles/13111/distinctions-of-iiot-services-how-its-helps-brands) what we are offering and what you are expecting. Hence every method present [inside the interface](https://answers.mindstick.com/qa/92499/why-can-t-you-specify-the-accessibility-modifier-for-methods-inside-the-interface) should be abstract.

**[Advantages](https://www.mindstick.com/articles/12841/5-advantages-of-customer-portal-you-didn-t-know-about) of interfaces:**

• We can achieve security because we are not highlighting internal implementation.

• Enhancement becomes easy because without affecting outside person we can change our internal implementation.

• Two different systems communicate via interface.

## Declaration and implementation of interface:

We can declare an interface using interface keyword and implement it using keyword implement.

```
interface intrf{
void m1();
void m2();
}
abstract class service provider implements intrf{
public void m1();
{
}
}
```

An interface is same written as a class. But a class describes the [attributes](https://www.mindstick.com/articles/13105/2-attributes-that-make-your-odoo-ecommerce-theme-productive-and-engaging) and behavior of an object. And an interface contains behaviors that a class implements.

If a class implements an interface compulsory we should provide implementation for every method of that interface otherwise we have to declare a class as abstract. Violation leads to compile time error.

## Extend vs interface:

1. A class can extend only one class at a time.

2. A class can implement any number of interfaces at a time.

3. A class can extend and can implement any no of interfaces simultaneously.

4. An interface can extend any no of interfaces

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