Square CSS

Monday, May 25, 2020

Java 8 : Static Method In Interface

Introduction


Java 8 comes with use of static method in an interface. Prior to Java 8 static method comes only on class level.

Refer The Video For More Detail



Uses of Static Method


We can create a method with static keyword and the method will be referred from the interface.


  public interface InterfaceWithStaticMethod {

public static void getStaticData() {
System.out.println("Data from static method of interface !!!");
}

}






  public class MainClass {

InterfaceWithStaticMethod.getStaticData();

}











The static method can be called in the class just by calling with interface having static method.











Conclusion


The static method can be created inside the interface since Java 8. It can be used by calling the Interface with its static method.


No comments:

Post a Comment

Some Algorithms

Algorithm: Tower of Hanoi

Tower of Hanoi consists of three towers called as pegs with n number of rings. Rings are of different size.  Conditions to be fulfill...

Popular Posts