Skip to content
Related Articles

Related Articles

Evolution of interface in Java
  • Difficulty Level : Basic
  • Last Updated : 16 Oct, 2017
GeeksforGeeks - Summer Carnival Banner

Prerequisite : Interfaces in Java
In Java SE 7 or earlier versions, an interface can have only:

  • Constant variables
  • Abstract methods

We can’t provide implementations of methods in interfaces.




public interface GFG{
      String a = "Geeksforgeeks is the best.";
      
      void hello(String a);
      void world(int x);
}

Java SE 8:
We can write method implementations in Interface from Java SE 8 and on-wards. We need to use “default” keyword to define them as shown below.
In Java SE 8 and later versions, an interface can have only four kinds of things:

  • Constant variables
  • Abstract methods
  • Default methods
  • Static methods




    public interface GFG{
          String b = "Shubham is a brilliant coder.";
        
          default void hello(String a){
             System.out.println("Hello");
          }
          static void world(int x){
             System.out.println("World");
          }
          void bye();
       }

    Java SE 9:
    In Java SE 9 and on-wards, we can write private methods in Interfaces using ‘private’ access modifier as shown below (like other private methods).
    In Java SE 9 and later versions, an interface can have:

    • Constant variables
    • Abstract methods
    • Default methods
    • Static methods
    • Private methods
    • Private Static methods




    public interface GFG{
          String b = "Shubham is a brilliant coder.";
        
          default void hello(String a){
             System.out.println("Hello");
          }
          static void world(int x){
             System.out.println("World");
          }
          void bye();
      
          private void great(long v){
               
          }
       }

    This article is contributed by Shubham Juneja. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

    Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

    Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.




    My Personal Notes arrow_drop_up
Recommended Articles
Page :