Search

Sunday, May 25, 2014

In Java , If two interfaces have same method signature and a class implements both , would it give problem ?

No , it would not give any problem if method is common and same signature it will implement as one within implemented class .
Example : Two interface as below :
Interface 1 :
public interface InterKap {
void show();
void abc();
int show(int k);
}

Interface :2
public interface InterKap2 {
void show();
void xyz();
int show(String k);
}

Implementing Class :
public class TestInerface implements InterKap , InterKap2 {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub

    }

    @Override
    public void show() {
        // TODO Auto-generated method stub
       
    }

    @Override
    public void xyz() {
        // TODO Auto-generated method stub
       
    }

    @Override
    public void abc() {
        // TODO Auto-generated method stub
       
    }

    @Override
    public int show(String k) {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public int show(int k) {
        // TODO Auto-generated method stub
        return 0;
    }

}

Cheers

Kapil

No comments:

Post a Comment