brunch

You can make anything
by writing

C.S.Lewis

by 서준수 Feb 17. 2019

Callback using interface

Callback using interface



public class dailyCode {
    public interface Callback {
        public void getOdd();
        public void getEven();
    }

    public static void main(String[] args){
        dailyCode.Callback callback = new dailyCode.Callback() {
            @Override
            public void getOdd() {
                System.out.println("getOdd");
            }

            @Override
            public void getEven() {
                System.out.println("getEven");
            }
        };

        for(int i=1; i<=5; i++){
            if(i%2==0) {
                callback.getEven();
            } else {
                callback.getOdd();
            }
        }
    }

}


매거진의 이전글 Singleton Design Pattern
브런치는 최신 브라우저에 최적화 되어있습니다. IE chrome safari