java - Why are there compile errors when accessing an Enum from the main method? -



java - Why are there compile errors when accessing an Enum from the main method? -

so i'm little bit confused i've never used enum before. want utilize enum in main method. reason, can't (i maintain getting errors anytime seek status s; in main). can phone call testingenum method main , of course of study works... 100% sure using enum way plain wrong. tell me how i'd go using in main properly?

if seek do: status s; in main method, error - "connot find symbol status s;"

background: new java , enums...

class myclass { public status s; public enum status { status_open(1), status_started(2), status_inprogress(3), status_onhold(4), status_completed(5), status_closed(6); private final int status; status(int stat) { this.status = stat; } public int getstatus() { homecoming this.status; } } private void setstatus(status stat) { s = stat; } public void testingenum() { status mystat = status.status_onhold; setstatus(mystat); } @override public string tostring() { stringbuilder result = new stringbuilder(); string new_line = system.getproperty("line.separator"); result.append(new_line + " status: " + s + new_line); homecoming result.tostring(); } } public class main { public static void main(string[] args) { myclass obj = new myclass(); // problem setting status here // can't this: status s; } }

move enum own class file, or access reference enclosing class.

it looks defined enum inner class of class. if you're doing this, need access syntax outerclass.status access it. made public, work. can access within class no problem because it's contained in scope of parent class.

so can either add together outerclass. before status, or can move enum own file other class.

java enums

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -