Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


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


How can we use enum data type in java program?


Advertisement
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  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 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 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 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 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 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 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 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"
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: 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
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
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
 

 

 

DMCA.com