Avoid implementing methods in interfaces – Java

I have the following interface:

public interface a {
    public void m1();
    public void m2();
    public void m3();
}

public class A implements a {
    public void m3() {
        // implementation code     
    }
}

I want to avoid implementing the rest of the methods One way is not to implement all the methods in the class that is trying to implement the interface

How can I avoid this situation The sample code can help me better understand:)

Solution

public interface a{
public interface a{

      public void m1();
      public void m2();
      public void m3();

}

public abstract class A implements a{

       public void m3(){

           // implementation code     

           }

}

Declared as an abstract class, so you don't need to implement these methods in this class But you must implement these methods in specific classes

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
分享
二维码
< <上一篇
下一篇>>