Friday, 17 February 2017

Default Method : Access other method within default method



 interface Summable {
    int getA();
    int getB();
    default int calculateSum() {
        return getA() + getB();    }
}

public class AccessOtherMethod implements Summable {
    @Override    public int getA() {
        return 1;    }

    @Override    public int getB() {
        return 2;    }

    public static void main(String[] args)
    {
        AccessOtherMethod accessOtherMethod = new AccessOtherMethod();        System.out.println( accessOtherMethod.getA() );        System.out.println( accessOtherMethod.getB() );        System.out.println( accessOtherMethod.calculateSum() );

    }
}

No comments:

Post a Comment