---
title: "How to implement interface in java? Please provide a sample."  
description: "How to implement interface in java? Please provide a sample."  
author: "Utpal Vishwas"  
published: 2023-09-05  
updated: 2023-09-06  
canonical: https://www.mindstick.com/forum/159835/how-to-implement-interface-in-java-please-provide-a-sample  
category: "java"  
tags: ["java", "interface"]  
reading_time: 2 minutes  

---

# How to implement interface in java? Please provide a sample.

How to implement [interface](https://www.mindstick.com/articles/12101/interfaces-in-java-extending-interfaces) in [java](https://www.mindstick.com/articles/12214/web-development-company-in-india-laid-on-the-foundation-of-concrete-java-programming)? Please provide a sample.

## Replies

### Reply by Aryan Kumar

A java interface is a blueprint for a class. Defines the methods that the class must implement. Interfaces cannot be instantiated, but can be implemented by classes.

Implementing an interface in Java, requires using the `implements` keyword. For example, the following code shows how the Runnable interface implemented:

Java

```plaintext
public class MyThread implements Runnable
{
    public void run()
    {
        // Do something.
    }
}
```

The `Runnable` interface defines a single method called `run()`. The `MyThread` class implements the `run()` method by providing its own implementation.

Here's another example of how to implementing an interface in Java:

Java

```plaintext
public interface Shape
{
    void draw();
}

public class Circle implements Shape
{
    public void draw()
    {
        // Draw a circle.
    }
}
```

The `Shape` interface defines a single method called `draw()`. The `Circle` class implements the `draw()` method by providing its own implementation.

If a class implements an interface, it must provide implementations for all the methods defined in that interface. A class is said to be an abstract class if it foes not provide implementations for all the methods defined in the interface, then the class is said to be `abstract`.


---

Original Source: https://www.mindstick.com/forum/159835/how-to-implement-interface-in-java-please-provide-a-sample

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
