avoid implementation of a method which is there in interface - java

Viewed 23438

I have a interface like the below :

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 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 :)

12 Answers

The implementation of every method is mandatory if you are using interface. However, you can avoid this by following the below approach:

  • Declare the missing methods abstract in your class. This forces you to declare your class abstract and, as a result, forces you to subclass the class (and implement the missing methods) before you can create any objects.
Related