Can we make a static method in interface ? if yes then how we call that method from an interface ?

is it possible to make a method Static in Interface ? if yes then how to call that method form interface ?


7 Answers
1-7 of  7
7 Answers
  • No, we cannot

  • By interface name

  • Hi My conct number 8074350844

  • No, because an interface contains only public abstract methods.

  • With Java 8, interfaces can have static methods. They can also have concrete instance methods, but not instance fields.

  • yes... from version 1.8 it is available but up to 1.7 interfaces support only abstract methods..
    if you declared static method in interface it distrub to all interface impleamented class...follow this code


    package youthforwork;

    public interface Youth {
        
         void run();
        static void test()
        {
            System.out.println(" we can declare static method ");
        }
        
        default void test1()
        {
            System.out.println("but it is available from 1.8 only");
        }
        

    }


    package youthforwork;

    public class Implemented implements Youth {
        
        public void run()
        {
            System.out.println(" executing / calling interface (STATIC) method in implemented class");
        }
        
        public static void main(String[] args) {
            
            
            
            
            Youth y=new Implemented();
            y.run();
            y.test1();
            Youth.test();
        }

    }



    EXECUTE THIS CODE 

Core Java

Didn't get the answer.
Contact people of Talent-Core Java directly by clicking here