Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Enum Problem

 
Mohit G Gupta
Ranch Hand
Posts: 634
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why cannot new constants of the
enum type MachineState be created ?

 
Ankit Garg
Sheriff
Posts: 9528
32
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You cannot instantiate enums on your own. enums only contain the constants declared inside of them. So you can do
Machine ob = Machine.ac
But you cannot do
Machine ob = new Machine();
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ankit Garg wrote:You cannot instantiate enums on your own. enums only contain the constants declared inside of them. So you can do
Machine ob = Machine.ac
But you cannot do
Machine ob = new Machine();


That's the intention of the enum.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic