Share on Google+Share on Google+

Naulej kumar
Enum data type
2 Answer(s)      4 years and 10 months ago
Posted in : Java Beginners

How can we use enum data type in java program?

Ads

View Answers

June 9, 2012 at 5:47 PM


Example

enum Fruits {
    APPLE(10), ORANGE(3), MANGO(5), LICHHI(10);
    Fruits(int quantity) {
        this.quantity = quantity;
    }

    int quantity;

    public int getQuantity() {
        return quantity;
    }
}

public class FruitsExample {
    Fruits fruits;

    public static void main(String[] args) {
        FruitsExample fruitsExample = new FruitsExample();
        fruitsExample.fruits = Fruits.APPLE;
        System.out.print(fruitsExample.fruits);
        System.out.print("(" + fruitsExample.fruits.getQuantity() + ")");
    }
}

Result Display

APPLE(10)

Description:- In this example we are using enum data type. Here we have defined Fruits as enum type by using the enum keyword. Now we will set some constant values APPLE, ORANGE etc in Fruits. Next define variable and its getter method. Now next step to declare a class named FruitsExample, having main method. We have create a object.now next step to call method.



June 9, 2012 at 5:47 PM


Example

enum Fruits {
    APPLE(10), ORANGE(3), MANGO(5), LICHHI(10);
    Fruits(int quantity) {
        this.quantity = quantity;
    }

    int quantity;

    public int getQuantity() {
        return quantity;
    }
}

public class FruitsExample {
    Fruits fruits;

    public static void main(String[] args) {
        FruitsExample fruitsExample = new FruitsExample();
        fruitsExample.fruits = Fruits.APPLE;
        System.out.print(fruitsExample.fruits);
        System.out.print("(" + fruitsExample.fruits.getQuantity() + ")");
    }
}

Result Display

APPLE(10)

Description:- In this example we are using enum data type. Here we have defined Fruits as enum type by using the enum keyword. Now we will set some constant values APPLE, ORANGE etc in Fruits. Next define variable and its getter method. Now next step to declare a class named FruitsExample, having main method. We have create a object.now next step to call method.










Related Tutorials/Questions & Answers:
Enum data type
Enum data type  How can we use enum data type in java program?  ... data type. Here we have defined Fruits as enum type by using the enum keyword. Now... data type. Here we have defined Fruits as enum type by using the enum keyword. Now
Enum Type
Enum Type       Enum... encounters an enum type, it generates a class that extends the java.lang.Enum... of enum type like Chandan, Ashish, Amar, Tamana via loop. Which
Advertisements
enum
enum  why we are not created child for enum type? why we are not extending any from enum
enum
enum  HOW TO INSERT enum constants at runtime into the enum
enum
enum  enum concept is developed based on class concept,but we can extend any class from our class,but why it is not passiable to extend by enum? every class in java directly and indirectly child class of Object class,every enum
Enum Data Types
Enum Data Types       Enum type is a type which consist of fixed set of constant fields. like direction... take an example of enum data types:   EnumTestResult.java
data type
data type  which data type is used to store video file in mysql databse
data type
data type  what are the date types in the java and vb.net? what is the difference between java and vb.net?   Hi Friend, java data types... vb.net data types are: Byte SByte Short UShort Integer UInteger Long ULong
alter data type
alter data type  alter data type of subName column for subject table to varchar(40
SERIAL data type
SERIAL data type   hello, What is SERIAL data type in MySQL?   hii, SERIAL is an alias for BIGINT UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE
MySQL Boolean Data Type
MySQL Boolean Data Type This example illustrates how create a boolean data type. In this example we create a table 't' where define four field that is 'a' which is BOOL type, 'b' which is FLOAT type, 'c' which is LONG VARCHAR type
Modify Data Type with ALTER Command
Modify Data Type with ALTER Command  Is it possible to modify the Data type of a column which has at least one data in it?If it is possible,then what will happen to the data in the column? Example. Table Name: Emp EmpName
Mysql Alter Data Type
Mysql Alter Data Type       Mysql  Alter Date Type is used to modify or change the Column... Alter Date Type'.To understand this example we create a table 'userform
Data type in java
Data type in java In this section we will tell you about data type in java. A data type is defined as " type of data that can be stored... of variable. By declaring the type of data, compiler restrict the user from
array accept all data type
array accept all data type  how can create array that accept all data type??? if we can solution it? how..   Hi Friend, Try the following code: import java.lang.reflect.*; class CreateArrayOfAllTypes{ public
array accept all data type
array accept all data type  how can create array that accept all data type??? if we can solution it? how..   Hi Friend, Try the following code: import java.lang.reflect.*; class CreateArrayOfAllTypes{ public
Data Conversion from double to another type
Data conversion is the conversion of data from one type to another type. In this section we will learn about data conversion from double primitive type to another data type like String, boolean and char etc
Data Conversion from long to another type
Data conversion is the conversion of data from one type to another type. In this section we will learn about data conversion from long primitive type to another data type like String, boolean and char etc
Data Conversion from float to another type
Data conversion is the conversion of data from one type to another type. In this section we will learn about data conversion from float primitive type to another data type like String, boolean and char etc
Data Conversion from short to another type
Data conversion is the conversion of data from one type to another type. In this section we will learn about data conversion from short primitive type to another data type like String, boolean and char etc
Data Conversion from byte to another type
Data conversion is the conversion of data from one type to another type. In this section we will learn about data conversion from byte primitive type to another data type like String, boolean and char etc
Data Conversion from int to another type
Data conversion is the conversion of data from one type to another type. In this section we will learn about data conversion from int primitive type to another data type like String, boolean and char etc
Data Conversion from String to another type
Data conversion is the conversion of data from one type to another type. In this section we will learn about data conversion from String primitive type to another data type like int, boolean and char etc
PHP Integer Data Type
Learn PHP Integer Data type: In PHP integers can be decimal which is a normal... data type is platform dependent. Usually the size of integer is 2 million in 32... type. PHP Integer Data Type Example: <?php $a=12; echo"
Data Type: number
Data Type: number       This Example shows you how to use number data type in velocity. Methods used in this example are described below:-  1:- Initialize velocity run
enum php mysql
enum php mysql  How to use mysql enum in php
need ENUM examples
need ENUM examples  i need enum sample examples
Data Type: String
Data Type: String       This Example shows you how to use string data type in velocity. ...: Display string data type variable.   DataTypeString.java
ENUM Types
ENUM Types A Enum type consist of a fixed set of constants. In java, you define an enum type by using the enum keyword. For example, you would specify a months-of-year enum type as: public enum Year{ January,February,March
need ENUM examples
need ENUM examples  i need enum sample examples   Hi Friend, Visit Here Thanks
need ENUM examples
need ENUM examples  i need enum sample examples   Hi Friend, Visit Here Thanks
Tutorials   
Java Spring Hibernate Struts Training Retrieve database from the table dynamically in jsp from oracle using servlet What does core Java include? java What are some way to learn Java quickly? Is it required to learn Java before learning Java Script? Is it necessary to learn java script before learning PHP? Are HTML5 and Java Script boosts Java career? Is Java object oriented? Fingerprint application with Java Uninstall Oracle Virtual Box JSON to HashMap Free Java online Training I want example of Control Statement in Java ANSI Color Codes with Python Create a Program that Calculates Input What is difference between JDK,JRE and JVM? How to see ubuntu version on server? How to get Page Source in Selenium (WebDriver) using Java? The path to the driver executable must be set by the webdriver.gecko.driver system property parse data from a link in java Java Program Qns using BlueJ How to fix HAX Kernel Module Is Not Installed error? Installing Audacity Looking for code Logic to check track changes & Coments in MSWord, MSWordx, MSExcel, MSExcelx is ON/OFF Installing JDK on Mac SAX Parser exception ERROR 601 (42P00): Syntax error. Encountered Thread java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory How to install Ubuntu 16.04 LTS? HttpServletRequest cannot be resolved to a type in eclipse - Solved Unhandled event loop exception GC overhead limit exceeded Spring Data jpa with apache phoenix Caused by: java.lang.IllegalArgumentException: Not a host:port pair: PBUF o.a.h.h.z.RecoverableZooKeeper - Possibly transient ZooKeeper, quorum= com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager class not found com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager not found How to download and install Java 8 on Windows? How to uninstall JDK 7? How to install gtk-doc-tools package in Ubuntu? How to install Oracle JDK 8 on Ubuntu? ejabberd_ctl.beam not found - Solved How to convert date to UTC format in Java? How to install autoconf, automake and libtool in Ubuntu 15.10? How to convert current date to mm dd yyyy format in Java? How to convert current date to dd mm yyyy format in Java? How to stop window closing in "internalFrameClosing" event. How to find list of all index in Neo4j? neo4j-server.properties file location SASLError using PLAIN: not-authorized

Ads

 
Advertisement null

Ads