Interface Static Method in Java 8 or Above

Dr. Vipin Kumar
Jan 23, 2021

Static Method in Interface

In earlier versions Java, before 1.8, it was not possible to create a static method in Interface, the only public abstract method was supported, but now from version 1.8, it is possible to declare static method also.

Let’s understand by example:

interface Message {

public abstract void msg ();

public default void msg2()

{

System.out.println(“Default method in Java”);

}

public static void msg3()

{

System.out.println(“Static method in Interface”);

}

}

public class Main implements Message {

public void msg ()

{

System.out.println(“This is Functional Interface Method”);

}

public static void main (String [] args)

{

Message m1 = new Main ();

m1.msg();

m1.msg2();

Message.msg3();

}

}

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Dr. Vipin Kumar
Dr. Vipin Kumar

Written by Dr. Vipin Kumar

Assoc. Prof. , DCA & Assoc. Head (SD), SDFS, at KIET, PhD (CS) My YouTube Channel: Dr. Vipin Classes (https://www.youtube.com/channel/UC-77P2ONqHrW7h5r6MAqgSQ)

No responses yet

Write a response