Naulej kumar
Enum data type
2 Answer(s)      11 months ago
Posted in : Java Beginners

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 Pages:
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
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 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
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
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
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
Java error class interface or enum excepted
in string of any  type of data in  the end of the invoking of string... Java error class interface or enum excepted... or enum excepted are the class of java error that occurred when a programmer
data type
data type  which data type is used to store video file in mysql databse
Enum Inversion Problem
have the enum type class available in the constructor of the ReverseEnumMap, so... with a sample enum of the type that we want to convert, such as: Communication<...Enum Inversion Problem This Article Discusses about Enum Inversion Problem
Inserting a value to an Enum field in Table
Inserting a value to an Enum field in Table  I'm writing a code..., password varchar (10), is_Admin enum('Y','N'), In the Java code I have a user... as a 'N' but I get some database error that says data truncated. How do I set
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 Column Type Database
  Column Type     Store Data... MySQL Column Type Database     ... of column in MySQL . MySQL supports the numeric type , Date and time type, and String
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
SCJP Module-1 Question-25
Given a sample code: 1    class Test { 2    public enum Man { 3    RAJ, SURAJ, DINESH, GUYS     }; 4    public static void main(String[] args) { 5 
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 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 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
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
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
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
need ENUM examples
need ENUM examples  i need enum sample examples
enum php mysql
enum php mysql  How to use mysql enum in php
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
SCJP Module-1 Question-13
Given a sample code: enum Year { JANUARY, FEBUARY, MARCH, APRIL, MAY, JUNE, JULY } class EnumTest { Year year; public EnumTest(Year year) { this.year = year; } public void tellItLikeItIs() { switch (year) { case JANUARY
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
about enum - Java Beginners
about enum  hi all, please tell me about "enum" and explain with example. And its use in OOP. Thanks
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
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
need ENUM examples
need ENUM examples  i need enum sample examples   Hi Friend, Try the following code: public class EnumExample { public enum Languages{ C, Java, DOTNET, PERL } public static void main(String[] args){ int
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
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
How to get enum value in Java
How to get enum value in Java  Hi all, i am looking for a solution to get an enum value from index in Java. Please suggest. Thanks
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
Reference type Vs Object type. - Java Beginners
Reference type Vs Object type.  Can anyone explain the exact... it with the data sent as arguments to a constructor. When created, assign... or object type variable which may reference a Book object or an object of any
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

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.