Share this post on:

Interface in Java is a medium to communicate two or more classes with each other. It is a special type of class which have by default static final data member and public abstract method. Interface in Java support 100% abstraction like abstract class we can not create its object. Interface keyword is used for declaring Interface.

Implements keyword : It is used for Interface Implementation. we can achieve multiple Inheritance using Interface.

Example

interface I1
{
    int a=6;
    public void display();
}
class TestDemo implements I1
{
    public void display()
    {
        System.out.println("Interface");
    }
    public static void main(String[] args)
    {

        I1 x = new TestDemo();
        x.display();
    }
}

Output: Interface

Example: How to use multiple Interface

interface I1
{
    public void display();
}
interface I2
{
    public void print();
}
class TestDemo implements I1, I2
{
    public void display()
    {
        System.out.println("Interface Display");
    }
    public void print()
    {
        System.out.println("Interface Print");
    }
    public static void main(String[] args)
    {
    I1 x=new TestDemo();
    I2 y=new TestDemo();
    x.display();y.print();

    }
}

Output:

Interface Display
Interface Print

Share this post on:
Avatar Raiyan

Author: Raiyan

Hi, I guess you're here because you want to know a bit about me. huh? I am not so good on talking about myself but I'll give a short about me.

My Name is Raiyan. I am a Professional Application Developer and a Blogger.
I started this website to Share my Knowledge. Here I provide all my knowledge whatever I earned till now.

3 Comments

  1. Pingback: How to use Threading in Java with Example - ArzaTechs

  2. Pingback: How to use Collection Framework in Java - ArzaTechs

  3. Pingback: What are Important topics in java for Interview? - ArzaTechs

Leave a Comment

Your email address will not be published. Required fields are marked *