How to write an interface with default and static method?
To write an interface with default and static methods in a programming language like Java, you can follow these steps:
- Declare an interface using the 
interfacekeyword. Specify the name of the interface and define the method signatures without providing any implementation. 
<span class="hljs-keyword">public</span> <span class="hljs-keyword">interface</span> <span class="hljs-title class_">MyInterface</span> {
    <span class="hljs-keyword">void</span> <span class="hljs-title function_">regularMethod</span><span class="hljs-params">()</span>; <span class="hljs-comment">// Regular method without implementation</span>
    <span class="hljs-keyword">default</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">defaultMethod</span><span class="hljs-params">()</span> {
        <span class="hljs-comment">// Default method implementation</span>
    }
    <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">staticMethod</span><span class="hljs-params">()</span> {
        <span class="hljs-comment">// Static method implementation</span>
    }
}
- Define regular method signatures without any implementation. These methods are the standard methods that implementing classes must override and provide their own implementation.
 - Define a default method using the 
defaultkeyword followed by the method signature and implementation. Default methods have a default implementation provided in the interface itself. Implementing classes can choose to override them or use the default implementation. - Define a static method using the 
statickeyword followed by the method signature and implementation. Static methods belong to the interface itself and cannot be overridden by implementing classes. 
Here’s an example of an interface with a regular, default, and static method:
<span class="hljs-keyword">public</span> <span class="hljs-keyword">interface</span> <span class="hljs-title class_">MyInterface</span> {
    <span class="hljs-keyword">void</span> <span class="hljs-title function_">regularMethod</span><span class="hljs-params">()</span>; <span class="hljs-comment">// Regular method without implementation</span>
    <span class="hljs-keyword">default</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">defaultMethod</span><span class="hljs-params">()</span> {
        System.out.println(<span class="hljs-string">"Default method implementation"</span>);
    }
    <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">staticMethod</span><span class="hljs-params">()</span> {
        System.out.println(<span class="hljs-string">"Static method implementation"</span>);
    }
}
Implementing classes can then implement this interface and provide their own implementation for the regular method if necessary. They can also choose to override the default method or use the default implementation directly. The static method is accessed using the interface name itself, without creating an instance of the implementing class.
Remember, the availability of default and static methods in an interface depends on the version of the programming language you are using. In Java, default and static methods were introduced in Java 8 and are not available in earlier versions.
