File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes enum doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Groovy Fundamentals video training course this week in the Groovy forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "enum doubt" Watch "enum doubt" New topic

enum doubt

zartab ameen

Joined: May 01, 2007
Posts: 13
Hi this is one of the question i found in mock exam

class Stepper{
enum Roman {I,V,X,L,C,M}
public static void main(String... bang){
int x=7;
int z=2;

Roman r=Roman.X;
case C:r=Roman.L;break;
case X:r=Roman.C;
case L:if(r.ordinal()>2)z+=5;
case M:x++;
i have just one statement which i did not understand

case L:if(r.ordinal()>2)z+=5;
please can you explain me what does above statement mean,i really don't
understand what ordinal is.

Julio Eneriz

Joined: Nov 28, 2007
Posts: 15
From the Api ( Enum page

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

So the behaviour depends on the ordinal I = 0, V = 1, X = 2 and so on, so L,C and M > 2.

What I'm not sure is the purpose of the code.
subject: enum doubt