Click to See Complete Forum and Search --> : use of enum:getting error


vaishnavi
03-12-2009, 12:20 PM
Hi all,

I am trying to define an enum in one class and use it in another class. below is my code. Can any one say what mistake I am doing:

import java.util.*;
class enumDemo
{
public enum Direction{NORTH,SOUTH,EAST,WEST}
}
public class Sprite
{
enumDemo.Direction d=Direction.NORTH;
public static void main(String args[])throws Exception
{
Sprite s=new Sprite();
System.out.print(s.d);
}
}

I am getting error like '; expected'

Deepak kumar D
03-18-2009, 07:52 AM
I think , by now you should have found the mistake that you did in the above code snippet. Any how i would like to share my solution for your query.

you have used the below line in your program, Where Direction.NORTH is unknown to class Sprite,
enumDemo.Direction d=Direction.NORTH;

Insted of this you should have done like this


enumDemo.Direction d=enumDemo.Direction.NORTH;

Let me know if u have any questions :).

vaishnavi
03-21-2009, 12:33 AM
Deepak,

I was still in a confusion until I read your post. Thanks that helped me solve my confusion...