I was reading an SCJP book by Khalid Mughal and I came across a statement

Enum constants are static members

and another

Enum constant is an instance of its enum type

. I am unable to reconcile the 2 statements. Are the constants static members or are they instances ? (Instances means using new, though we can't ourselves create instances of the enum type)

Recommended Answers

All 5 Replies

public static Integer one = new Integer(1);

one is a static member that is an instance of the Integer type. Same same.

Thanks. But static methods can only access other static members, then will main be able to access a member thats static as well as instance ?

Why and when should I declare a member as static as well as instance ?

A member can't be both static and instance.
I think there may be confusion between references and objects here. In masijade's example
one is a reference variable. It is static.
new Integer(1) is an object. It's an instance of the Integer class.
Instance variables are not the same as instances of a class; I agree, using the same word for both is confusing.

You are confusing things. An enum is static, it always is. Just like "one" in my example above. That statement that says it is "an instance of enum" means that that static member is an enum, and not a String, or Integer, or whatever. In exactly the same way that "one" above is an instance of Integer. It simply means that "one" is an Integer and not a String, or Enum, etc.

Thanks. I got it. I was confusing instances with instance members (which are nothing but non-static members associated with a particular instance of a class)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.