---
title: "Interface in Java"  
description: "In this article I am explaining about Interface in Java"  
author: "Manoj Pandey"  
published: 2015-04-18  
updated: 2019-09-07  
canonical: https://www.mindstick.com/articles/1731/interface-in-java  
category: "java"  
tags: ["java"]  
reading_time: 2 minutes  

---

# Interface in Java

An interface in the Java [programming language](https://www.mindstick.com/articles/332896/top-5-programming-languages-for-ios-app-development) is an abstract type that is used to specify an interface (in the generic sense of the term) that classes must implement.\

##### An interface is similar to a class in the following ways:

- An interface contains number of methods, not body of method.
- An interface is written in a file with a .java extension as same as [class name](https://www.mindstick.com/forum/12871/how-to-get-class-name) extension.
- The bytecode of an interface appears in a .[class file](https://www.mindstick.com/forum/60/how-we-add-dll-with-other-class-file).
- [Interfaces](https://www.mindstick.com/articles/26/interfaces) appear in packages, and their corresponding bytecode file must be in a directory structure that matches the package name.

A Java class can only extend one parent class. [Multiple inheritance](https://www.mindstick.com/forum/159471/how-does-c-plus-plus-support-multiple-inheritance-and-what-are-potential-issues-associated-with-it) is not allowed. Interfaces are not classes, however, and an interface can [extend more than one](https://answers.mindstick.com/qa/31899/why-is-an-interface-be-able-to-extend-more-than-one-interface-but-a-class-can-t-extend-more-than-one-class) parent interface.

##### For example

```
Public interface MyInterface extends Class1, Class2  {}
```

For access interface in class use below syntax

class Sample implements MyInterface

##### Rules for Interfaces:

- An interface is implicitly abstract. You do not need to use the abstract keyword when declaring an interface.
- Each method in an interface is also implicitly abstract, so the abstract keyword is not needed.
- Methods in an interface are implicitly public.
- Interface cannot be declared as private, protected or transient.
- Variables declared in interface are public, static and final by default.

##### Relationship between classes and interface

![Interface in Java](https://www.mindstick.com/mindstickarticle/e02ed970-8ad8-4cc9-8cc8-2778b1650aa4/images/32119ad3-0753-4f54-b428-c472736914d8.png)

Here I am creating a sample of multiple interfaces

```
interface Interface1 {     public void demo();} interface Interface2 {     public int Addition(int a, int b);} class Sample {      public static void main(String arg[]) {           Sample2 sam2 = new Sample2();           sam2.demo();           System.out.print(" Addition -: " + sam2.Addition(5, 6));      } } class Sample2 implements Interface1, Interface2 {     @Override     public void demo() {           // TODO Auto-generated method stub           System.out.println("Interface1 Method");      }      @Override     public int Addition(int a, int b) {           // TODO Auto-generated method stub           a = a + b;           return a;      }} 
```

Output-:

Interface1 Method

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