Enum data type

Ads
 

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.

Ads









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
data type
data type  which data type is used to store video file in mysql databse
Advertisements
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
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
enum  why we are not created child for enum type? why we are not extending any from 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
enum
enum  HOW TO INSERT enum constants at runtime into the enum
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 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 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 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 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 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 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
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
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... Alter Date Type'.To understand this example we create a table 'userform
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 '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
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
Mysql Alter Data Type
Mysql Alter Data Type       Mysql  Alter Date Type is used to modify or change the Column... on 'Mysql Alter Date Type'.To understand this example we create a table
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... in case of narrowing i.e. when a data type requiring more storage is converted
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
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

Ads