---
title: "What are default and static methods in interfaces in java?"  
description: "What are default and static methods in interfaces in java?"  
author: "Revati S Misra"  
published: 2024-07-19  
updated: 2024-07-19  
canonical: https://www.mindstick.com/forum/160958/what-are-default-and-static-methods-in-interfaces-in-java  
category: "java"  
tags: ["java", "interface", "methods", "programming language"]  
reading_time: 2 minutes  

---

# What are default and static methods in interfaces in java?

What are [default](https://www.mindstick.com/interview/12771/what-is-the-importance-of-default-resources) and [static methods](https://www.mindstick.com/forum/161339/static-methods-in-python) in [interfaces](https://www.mindstick.com/articles/12100/interfaces-in-java-real-life-example) in java?

## Replies

### Reply by Ashutosh Patel

#### Default and Static Methods in Interface

In Java 8 and later versions, interfaces have gained the ability to have default and [static](https://www.mindstick.com/articles/12098/the-static-keyword-the-static-methods) [methods](https://www.mindstick.com/articles/13060/runny-nose-remedy-methods-that-work-best), which provide additional capabilities and flexibility in interface definition

#### Default Methods in Interfaces

## Definition

- A default method on the interface is a method that provides a default implementation on the interface itself.
- It allows you to add new methods to interfaces without breaking existing implementations.
-

## Syntax

- The default methods are defined using the default keyword after which a signed method is used.
- They have to have a rule group.

## Example-

```plaintext
public interface MyInterface {
   void normalMethod();  // Abstract method
   default void defaultMethod() {
       System.out.println("Default method implementation");
   }
}
```

**Usage**\

- The class implementing the interface can choose to override the default method if they want to provide different functionality.
- If unchecked, the default route from the interface is used.

## Purpose

- Standardized methods allow interfaces to evolve by adding additional methods without forcing all implementation classes to immediately provide implementation.
- They provide a way to extend interfaces in a backward compatible manner.

#### \
Static Methods in Interfaces

## Definition

- Static methods in interfaces are similar to static methods in classes.
- They are associated with the interface itself rather than with any instance of the interface.

## Syntax

- Static methods are defined using the static keyword followed by the method signature and implementation.
- They have to have a rule group.

## Example-

```plaintext
public interface MyInterface {
   void normalMethod();  // Abstract method
   default void defaultMethod() {
       System.out.println("Default method implementation");
   }
   static void staticMethod() {
       System.out.println("Static method in interface");
   }
}
```

## Usage

- Static methods on interfaces can be called by the interface name, e.g., `MyInterface.staticMethod()`.
- They provide methods for interface-specific benefits that do not depend on any instance-specific data.

\
**Purpose**

- Static methods on interfaces can provide auxiliary methods, factory methods, or other utility methods associated with the functionality defined by the interface.
- They improve code organization and can be used to avoid duplication of utility methods across multiple implementation classes.

**Also, Read:** [Discuss the advantages and disadvantages of using recursion versus iteration in Java programming.](https://www.mindstick.com/forum/160956/discuss-the-advantages-and-disadvantages-of-using-recursion-versus-iteration-in-java-programming)


---

Original Source: https://www.mindstick.com/forum/160958/what-are-default-and-static-methods-in-interfaces-in-java

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
