Implementation of abstract method definition for enumeration types

Source: Internet
Author: User

Implementation of abstract method definition for enumeration types


Package com. lc. day02.EnumTest; import org. junit. test; public class implements actenumtest {@ Testpublic void test () {print (Grade1. B);} public void print (Grade1 g) {String val = g. localValue (); System. out. println (val) ;}} enum Grade1 {// A, B, C, D, E; // The objects A ("100-90") {public String localValue () {return "" ;}} generated by the five non-parametric constructors of the class ";}}, B ("89-80") {public String localValue () {return "good" ;}}, C ("79-70") {public String localValue () {return "normal" ;}}, D ("69-60") {public String localValue () {return "poor" ;}}, E ("59-0 ") {public String localValue () {return "fail" ;}}; private String value; private Grade1 (String value) {// The enumeration Type constructor should be private this. value = value;} public String getValue () {return this. value;}/** abstract methods in enumeration must be defined when an object is created */public abstract String localValue ();}


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.