java enum class example

Read about java enum class example, The latest news, videos, and discussion topics about java enum class example from alibabacloud.com

Java Inner Class (5): application Example

Public voidg () { - y.f (); - } - } - - classTest008subextendsEGG2 { in Publictest008sub () { -System.out.println ("AA"); toInsertyolk (Newyolk ()); + } - the Public classYolkextendsEgg2.yolk { * Publicyolk () { $System.out.println ("Bigegg2.yolk ()");Panax Notoginseng } - the Public voidf () { +System.out.println ("Bigegg2.yolk.f ()"); A } the } + } - $ //order of calls in complex cases $ Public classTest008 { - Public Stat

An example of a Java inner class

Package jsckson;/******************************************** * File name: threadLocal An example of a Java inner class

One way to use enum-type enums in Java

The enumeration class is defined as follows:Package com.qunar.enumtest; Public enumStatus {scuuess ("1","Success"), FAILED ("2","Failed");PrivateStringvalue;PrivateString desc; PublicStringGetValue() {return value; } Public void SetValue(Stringvalue) { This.value=value; } PublicStringGetDesc() {returnDesc } Public void Setdesc(String desc) { This. desc = desc; }Private Status(Stringvalue, String desc) { This.value=value; This. desc = desc; }}Use the f

Use of enum enumerations in Java

Note Item:1. Using enumerations in switch can make your code more readable. 2. If you want to customize a method, you must add a semicolon at the end of the enum instance sequence.And Java requires that an enum instance be defined first.3. All enumerations inherit from the Java.lang.Enum class, and because

Common uses of Java enumeration (enum)

JDK1.5 introduces a new type--enumeration. In Java, although it is a "small" function, but to my development has brought "big" convenience.Usage One: constant.Before JDK1.5, we defined constants: public static fianl ..... Now, with enumerations, you can group related constants into an enumeration type, and enumerations provide more methods than constants. Public enum Color { RED, GREEN, BLANK, YELLOW}Si

Effective Java version 2nd-notes (01) enumeration (enum) implementation of a singleton (Singleton)

Directly on the code:1 Public enumBoss {2 3 INSTANCE;4 5 PrivateString name;6 7 Public voiddosomething () {8SYSTEM.OUT.PRINTLN (name + "is doing something now ...");9 }Ten One PublicString GetName () { A returnname; - } - the Public voidsetName (String name) { - This. Name =name; - } - +}Note: The enum in Java is a thoroughly-bottomed

Java programming: attaches methods to enumeration constants in enumeration enum

Java programming: attaches methods to enumeration constants in enumeration enum Package enumeration; // append the method to the enumerated constant public class UnitsConverter {private static double numberToConvert = 0; public static void main (String [] args) {// TODO Auto-generated method stub if (args. length = 0) {System. out. println ("Usage:

One way to use Enum in Java

/** * Created by Lzd on 2018/3/31. */public class Enumprac {public enum demo{SUCCESS (1, "success"), Fail (0, "failed"); Private Integer Code; Private String desc; Private Demo (Integer code, String desc) {this.code = code; THIS.DESC = desc; } public Integer GetCode () {return code; } public String GetDesc () {return desc; } public void Setcode (In

Use of the Java Enum enumeration

/*** Use of Java enumerations* @author RSun* @Date 2012-11-7 11:46:08*/public class Enumtest {public static void Main (string[] args) {System.out.println ("Using enumerations:" + T.AA);SYSTEM.OUT.PRINTLN ("Use enumeration ID:" + t.aa.getid ());SYSTEM.OUT.PRINTLN ("Use enumeration value:" + t.aa.getvalue ());System.out.println ("Get enumeration property by name:" + t.valueof ("AA"). GetId ());}public

Simple use of Java enumerations (enum)

Enumerations are similar to classes and are defined in 2 ways: code example: publicenumsysenumconstant{taskcreat{//Task Creation publicstringgetstatus () {return "0";} },TASKSTART{publicString GetStatus () {return "1";} },taskassign{//Task Dispatch publicstring getstatus () {return "2";} },taskexe{//Task Execution publicstring getstatus () {return "3";} },taskend{//Task End publicstring getstatus () {return "4";} },taskcancel{//task v

Java Enumeration type Enum

Import java. util. enumset; /** Production date: 2009/06/18*/ /*** Todo content record** @ Author itsuser* @ Lastupdate $ Date: $* @ Lastmodified $ author $* @ Version $ revision $* @ Since 2009/06/18**/Public class enumtest { Public Enum color {red, orangle, yello, green, cyan, blue, purple };Public Enum week {Su

RHYTHMK Step-by-step JAVA: Enum Enumeration Learning

Enumeration definition: Public enum Sizeenum { SMALL, BIG, BIGEST}; Public enumsizestringenum {SMALL ("Small"), BIG ("Big"), BIGEST ("Huge"); PrivateString strsizestring; PublicString toString () {returnstrsizestring; } Privatesizestringenum (String str) { This. strsizestring =str; }}Common methods:1. VALUES ():Gets all object properties for the current enumeration:Such as:// 1. Sizestringenum sizestringenum=sizestringenum.big;

How to use Java enum

() Public intToInt () {return This. Value; } PublicString Totext () {return This. Text; } //you can define a static method to get text based on value (provides methods for an enumeration class)//Testenum.gettext (1) Public StaticString GetText (intvalue) { for(Testenum item:TestEnum.values ()) {if(Value = =item.value) {returnItem.text; } } return NULL; } //you can override the

Java Enum Enumeration

1. Code Import java. lang. *; // enum showing Mobile pricesenum Mobile {Samsung (400), Nokia (250), Motorola (325); int price; Mobile (int p) {price = p ;} int showPrice () {return price;} public class EnumDemo {public static void main (String args []) {System. out. println ("CellPhone List:"); for (Mobile m: Mobile. values () {System. out. println (m + "costs

One way to use enum-type enums in Java

The enumeration class is defined as follows:Package com.qunar.enumtest; Public enumStatus {scuuess ("1","Success"), FAILED ("2","Failed");PrivateStringvalue;PrivateString desc; PublicStringGetValue() {return value; } Public void SetValue(Stringvalue) { This.value=value; } PublicStringGetDesc() {returnDesc } Public void Setdesc(String desc) { This. desc = desc; }Private Status(Stringvalue, String desc) { This.value=value; This. desc = desc; }}Use the f

Enum in Java

Package Com.st.java; /** @author*/publicenum moneytype { Zero_point_one, zero_point_five, One, FIVE, TEN, Twenty, fity, hundred }Package Com.st.java;public class Moneytypetest {public static void main (string[] args) {testenum (); Testswitch (Moneytype.one); Testswitch (moneytype.fity);} public static void Testenum () {for (Moneytype mt:MoneyType.values ()) {//ordinal: Constant Declaration order

Java Select a specific value 2--abstract enum

//print a specific value; Public classDemo1 { Public voidTest () {print (GRADE.A); } Public voidPrint (Grade Grade) {//print a specific value;String value=Grade.localvalue (); System.out.println (value); } /** Method One static class Grade{public Grade () {} private static final Grade A =new Grade (); private static final Grade b=new Grade (); private static final Grade c=new Grade (); private static final Grade d=ne

Java Nested Class (Nested Class): Static nested class, inner class, local class, anonymous class

anonymous classes without the class keyword?1) to have the new operator, similar to the normal class instantiation of an expression.2) to implement an interface or inherit a class, the example above is to implement the HelloWorld interface.3) class body (body), where you ca

Java internal class (InnerClass) ---- non-static internal class, static internal class, local internal class, anonymous internal class

a c ++ nested class is whether it points to external class references. Of course, there are some differences from the design details and some other perspectives. In addition, no non-static internal class can have static data, static methods, or another static internal class (internal

Java Tour (ix)--object class, Equals,tostring,getclass, inner class access rule, static inner class, Inner class principle, anonymous inner class

Java Tour (ix)--object class, Equals,tostring,getclass, inner class access rule, static inner class, Inner class principle, anonymous inner class Every day by some trivial harassment, learning to continue I. Object

Total Pages: 15 1 .... 9 10 11 12 13 .... 15 Go to: Go

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.