避免实现接口中的方法 - java [英] avoid implementation of a method which is there in interface - java

查看:167
本文介绍了避免实现接口中的方法 - java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有如下界面:

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

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

我想避免对方法的其余部分实施。一种方法是让所有方法都没有在类中实现,试图实现 interface

I want to avoid implementation for the rest of the method. one way is to have all the methods without implementing in the class that tries to implement interface.

我如何避免这种情况示例代码可以帮助我更好地理解:)

How do I avoid this. Example code would help me understand better :)

推荐答案

public interface a{

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

}

public abstract class A implements a{

       public void m3(){

           // implementation code     

           }

}

声明为抽象class所以你不需要在这个类中实现这些方法。但是你必须在具体的类

Declare as abstract class so you will not needed to implement these methods in this class. But you have to implement those method in concrete class

这篇关于避免实现接口中的方法 - java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆