This question already has an answer here:
- java compiled classes contain dollar signs 4 answers
When i compile my java Enum Day, it generates his Day.class file and 8 Day$#.class Files, so i want to know why the compiler generates 8 $#.class instead of 7, because i have 7 enum constants, but 8 override annotations, i have understood that the Dollar.class files are generated for every inner class or by enum constants, but what about the eight .class file what it is generated for?
package com.kaissersoft.test.objective.one.three.enums;
public enum Day{
SUNDAY(01){
@Override
public void salute(){
System.out.println("Today is Sunday");
}
},
MONDAY(02){
@Override
public void salute(){
System.out.println("Today is Monday");
}
},
TUESDAY(03){
@Override
public void salute(){
System.out.println("Today is Tuesday");
}
},
WEDNESDAY(04){
@Override
public void salute(){
System.out.println("Today is Wednesday");
}
},
THURSDAY(05){
@Override
public void salute(){
System.out.println("Today is Thursday");
}
},
FRIDAY(06){
@Override
public void salute(){
System.out.println("Today is Friday");
}
},
SATURDAY(07){
@Override
public void salute(){
System.out.println("Today is Saturday");
}
};
int dayNumber;
Day(final int day){
dayNumber = day;
}
public int getDayNumber(){
return dayNumber;
}
@Override
public String toString(){
switch(this){
case SUNDAY:
System.out.println("Sunday("+this.getDayNumber()+")");
break;
case MONDAY:
System.out.println("Monday("+this.getDayNumber()+")");
break;
case TUESDAY:
System.out.println("Tuesday"+this.getDayNumber()+")");
break;
case WEDNESDAY:
System.out.println("Wednesday("+this.getDayNumber()+")");
break;
case THURSDAY:
System.out.println("Thursday("+this.getDayNumber()+")");
break;
case FRIDAY:
System.out.println("Friday("+this.getDayNumber()+")");
break;
case SATURDAY:
System.out.println("Saturday("+this.getDayNumber()+")");
break;
}
return super.toString();
}
//Abstract method to the day Salute
public abstract void salute();
}
And it generates this:
- Day.class
- Day$1.class
- Day$2.class
- Day$3.class
- Day$4.class
- Day$5.class
- Day$6.class
- Day$7.class
- Day$8.class