Enum data type

Enum data type

How can we use enum data type in java program?

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... for a variable of enum type like Chandan, Ashish, Amar, Tamana via
Advertisements
enum
enum  why we are not created child for enum type? why we are not extending any from enum
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
Enum Data Types
Enum Data Types       Enum type is a type which consist of fixed set of constant fields. like direction..._TO_REPLACE_1 Lets take an example of enum data types:   EnumTestResult.javaADS
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
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,ADS_TO_REPLACE_1 SERIAL is an alias for BIGINT UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE
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
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 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 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
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
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
Mysql Alter Data Type
Mysql Alter Data Type       Mysql  Alter Date Type is used to modify or change the Column... an example on 'Mysql Alter Date Type'.To understand this example we create a table
PHP Integer Data Type
Learn PHP Integer Data type: In PHP integers can be decimal which is a normal... size of the integer data type is platform dependent. Usually the size of integer... be converted to float data type. PHP Integer Data Type Example:ADS_TO_REPLACE_2 <
ModuleNotFoundError: No module named 'data_type_tools'
ModuleNotFoundError: No module named 'data_type_tools'  Hi, My... named 'data_type_tools' How to remove the ModuleNotFoundError: No module named 'data_type_tools' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'algebraic-data-type'
ModuleNotFoundError: No module named 'algebraic-data-type'  Hi, My... named 'algebraic-data-type' How to remove the ModuleNotFoundError: No module named 'algebraic-data-type' error? Thanks   Hi
ModuleNotFoundError: No module named 'data_type_tools'
ModuleNotFoundError: No module named 'data_type_tools'  Hi, My... named 'data_type_tools' How to remove the ModuleNotFoundError: No module named 'data_type_tools' error? Thanks   Hi, In your python
Data Type: String
Data Type: String       This Example shows you how to use string data type in velocity. ... variable. $str: Display string data type variable.  
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
data type used to store name.(getting an error)
data type used to store name.(getting an error)    Statement stm=con.createStatement(); String query="select * from employee where ename=\'"+ename+"\'"; ResultSet rs=stm.executeQuery(query
Conversion from string data type into different data types.
Conversion from string data type into different data types.  string str="World id Beutifull"; char chr[20]; char* chrctr ; Qustion is -How to store the 'str' value in 'chr' and 'chrctr'? int abc; sprintf(abc ,"%s",str
Identify Excel's cell data type
Identify Excel's cell data type In this section, you will learn how you can identify cell's data type and handle it appropriately using Apache POI. In Apache POI library, for fetching each type of data, there is separate
Get date data type from table
GET DATE DATA TYPE FROM TABLE In this example , we will get "Date" data type from a table of "Mysql" database and it also display... data = rs.getString(2);                 System.out.println(name +"\t"+data
Convert integer type data into binary, octal and hexadecimal
Convert integer type data into binary, octal and hexadecimal... will learn how to convert an integer type data into binary, octal and hexadecimal... into these. toBinaryString() method converts integer type data into binary
Java program to get data type of column field
Java program to get data type of column field  ... the data type of the database table fields. For this purpose we have established... tables meta data for getting the data type of the table columns. Here we have
need ENUM examples
need ENUM examples  i need enum sample examples
enum php mysql
enum php mysql  How to use mysql enum in php
difference between enum and final class?
difference between enum and final class?  what is the difference between enum and final class in java?   The java.lang.Enum is an abstract.... The definition of Enum is: public abstract class Enum> extends Object implements
Hi Friend. on Default Data type Values - Java Beginners
Hi Friend. on Default Data type Values  Hi ... I have doubt on Default Data types... Is it Possible to print the Dafault Values..If it s so, Check this code..How to Print d Default Values
Mysql Alter Data Type
Mysql Alter Data Type       Mysql  Alter Date Type is used to modify or change the Column... cover an example on 'Mysql Alter Date Type'.To understand this example we
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
ModuleNotFoundError: No module named 'enum'
ModuleNotFoundError: No module named 'enum'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'enum' How to remove the ModuleNotFoundError: No module named 'enum' error
ModuleNotFoundError: No module named 'enum'
ModuleNotFoundError: No module named 'enum'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'enum' How to remove the ModuleNotFoundError: No module named 'enum' error
JDOM Attribute Example, How to convert value of attribute in different data type
data type In this tutorial, we will see how to retrieve the value of an attribute in different data type like int, float, boolean etc with the help of JDOM..., if there is some data conversion error, it throws the DataConversionException
need ENUM examples
need ENUM examples  i need enum sample examples   Hi Friend, Visit HereADS_TO_REPLACE_1 Thanks
need ENUM examples
need ENUM examples  i need enum sample examples   Hi Friend, Visit HereADS_TO_REPLACE_1 Thanks
Casting (Type Conversion)
; It is sometimes necessary to convert a data item of one type to another type. Conversion of data from one type to another type is known as type...) Automatic type casting does work in case of narrowing i.e. when a data type
about enum - Java Beginners
about enum  hi all, please tell me about "enum" and explain with example. And its use in OOP. Thanks
how to write the coding for converting the database data for example population into any type of graph using jsp and servlets?//
coding for converting the database data  how to write the coding for converting the database data for example population into any type of graph using... the database data for example population into any type of graph using jsp and servlet
need ENUM examples
need ENUM examples  i need enum sample examples   Hi Friend, Try the following code:ADS_TO_REPLACE_1 public class EnumExample { public enum Languages{ C, Java, DOTNET, PERL } public static void main(String

Ads