oop - What is this thing called in Java? -


google isn't being friendly today, , i'm researching oop techniques i've not used in past.

basically, i've noticed libraries have variables preset choices, new website(websites.stackoverflow). called, when you've got apparently immutable values that? if want create own one, colours.red , colours.green?

i hope can tell me called allow me continue research! thank you.

edit: i'm not marking duplicate because couldn't figure out how accurately describe looking - i'm thinking it's quite possible else may have similar difficulties , might find useful. if i'm wrong, that's okay.

they called enumerations. can find detailed info here

they defined as:

public enum day {     sunday, monday, tuesday, wednesday,     thursday, friday, saturday  } 

and used as:

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();         enumtest sixthday = new enumtest(day.saturday);         sixthday.tellitlikeitis();         enumtest seventhday = new enumtest(day.sunday);         seventhday.tellitlikeitis();     } } 

and output be:

mondays bad. midweek days so-so. fridays better. weekends best. weekends best. 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -