java - Need to use Enum -
i clear advanced use of enum in java. many of points differentiate them regular classes , tells need clear me.
can give practical example sample code advanced enum? can elaborate
where should avoid classes , should use enum instead
.
please dont confused. not asking how use enum or use of enum. there many questions , answers on this. looking real time/ live / practical example should avoid other data type or classes.
try this example:
public enum day { sunday, monday, tuesday, wednesday, thursday, friday, saturday }
usage:
public class enumtest { day day; public enumtest(day day) { this.day = day; } public void tellitlikeitis() { switch (day) { case monday: system.out.println("mondays bad."); break; case friday: system.out.println("fridays better."); break; case saturday: case sunday: system.out.println("weekends best."); break; default: system.out.println("midweek days so-so."); break; } } public static void main(string[] args) { enumtest firstday = new enumtest(day.monday); firstday.tellitlikeitis(); enumtest thirdday = new enumtest(day.wednesday); thirdday.tellitlikeitis(); enumtest fifthday = new enumtest(day.friday); fifthday.tellitlikeitis(); } }
Comments
Post a Comment