简体   繁体   中英

Why doesn't this Java enum code compile?

enum itProfs {  
    private int sal;
    DEVELOPER(30), ANALYST(20); 
    itProfs(int sal){
        this.sal = sal;
    }
    public int getSal(){
        return sal;
    }   
}

What is the reason?

You should put enumeration values first.

enum itProfs {  
    DEVELOPER(30), ANALYST(20); 
    private int sal;
    itProfs(int sal){
        this.sal = sal;
    }
    public int getSal(){
        return sal;
    }   
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM