Saturday, 10 June 2017

Java Tutorial: Enum in java[Ordinal method of enum - mobile] ~ foundjava


Click here to watch in Youtube : 

https://www.youtube.com/watch?v=aEePhT_ZTEA&list=UUhwKlOVR041tngjerWxVccw

EnumDemo.java

enum Mobile
{
    Samsung, Nokia, Motorola;
}

public class EnumDemo
{
    public static void main(String args[])
    {
        Mobile mobile = Mobile.Nokia;

        /*
         * Returns the ordinal of this enumeration constant
         * (its position in its enum declaration, where the
         * initial constant is assigned an ordinal of zero).
         */

        int ordinal = mobile.ordinal();
        System.out.println("The ordinal is = " + ordinal);

    }
}
Output
The ordinal is = 1
Click the below link to download the code:

CLICK HERE

No comments:

Post a Comment