What is the use of Java object-oriented enum enumerated types
This article mainly shows you "what is the use of Java object-oriented enum enumeration types", the content is easy to understand, well-organized, hope to help you solve your doubts, the following let Xiaobian lead you to study and learn "what is the use of Java object-oriented enum enumeration types" this article.
/ * * 1. Constants: variables modified with final * Note: constants follow the naming rules for identifiers, generally uppercase * * 2. Enum enumerated types: follow the naming rules for identifiers Acronym capital * enumeration type: is a special qualified constant type * advantage: limit value * * / public class Test1 {public static void main (String [] args) {/ / instantiate the red circle Circle red = new Circle (5, Color.RED) / / red.PI=1000; red.draw (); / / instantiate the green circle Circle green = new Circle (10, Color.GREEN); green.draw (); / / instantiate the blue circle Circle blue = new Circle (20, Color.BLUE); blue.draw () }} / / define the enumerated type enum Color {RED, GREEN, BLUE} class Circle {this.r r; radius of circle final double PI = 3.14; color of constant Color color;// circle (0: red 1: green 2: blue) public Circle (double r, Color color) {this.r = r; this.color = color } / / calculate the area of a circle public double getArea () {return PI * r * r;} / / draw a circle public void draw () {String colorName = ""; if (color = = Color.RED) {colorName = "red" } if (color = = Color.GREEN) {colorName = "green";} if (color = = Color.BLUE) {colorName = "blue" } System.out.println ("make the area:" + getArea () + "Color:" + colorName + "draw a circle on the screen");}} above is all the content of the article "what is the use of Java object-oriented enum enumerated types". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!