korayucar
7/7/2016 - 9:07 AM

A toy code to demonstrate need for private abstract method. It is forbidden in java but it has a valid use.

A toy code to demonstrate need for private abstract method. It is forbidden in java but it has a valid use.

 enum Count{
    SINGLE { 
        private int howMany() {
            return 1;
        }
    },
    DOUBLE{ 
        private int howMany() {
            return 2;
        }
    };  
    private abstract int howMany();// !! this declaration is illegal
    public boolean isMultiple(){
        return this.howMany() > 1;
    }
}

public static void main (String... args){
    System.out.println(Arrays.toString(Count.values()));
    for(Count s : Count.values()){
        System.out.println(s.howMany() + " is " + (s.isMultiple() ? "many" : "one"));
    }
}