Implement within the interface – Java
•
Java
We know that we cannot implement functions in interfaces in Java
I just tried
public interface InvoiceService { public static void getData(){ System.out.print("this is my data"); } }
I can perform this function. Why? Is it because functions are defined as static and static variables that can be accessed directly using class names without creating objects?
Solution
Because you may be using java 8 In Java 8, you can add static methods and default methods to the interface Read more about static and default methods in the Java 8 documentation
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码