Return to site

☕🎓JAVA CERTIFICATION QUESTION: Which of these statements about enum are nor correct?

· java,ocp

* It cannot be declared with the keyboard abstract

* It cannot be declared with the keyword final

* It can be declared as static nested class or inner class

* It cannot be directly instantiated

* Its direct supertype is always Enum

#java #certificationquestion #ocp

1. and 2. "It cannot be declared with the keyword abstract." and "It cannot be declared with the keyword final."

- This statements are correct.

According to Java Specification Language 8.9 (JLS 8.9) (https://docs.oracle.com/javase/specs/jls/se8/html/jls-8.html#jls-8.9):

It is a compile-time error if an enum declaration has the modifier abstract or final.

3. "It can be declared as a static nested class or inner class."

- This statement is not correct.

According to JLS 8.9: it is impossible to declare an enum type in the body of an inner class (§8.1.3),

because an inner class cannot have static members except for constant variables.

4. "It cannot be directly instantiated."

- This statement is correct.

According to JLS 8.9: You cannot create instances of an enum using the `new` keyword.

Enums are typically used to represent a fixed set of constants, and their instances are predefined and limited to the values declared within the enum.

5. "Its direct supertype is always Enum."

- This statement is correct.

According to JLS 8.9: The direct supertype of an enum is always `java.lang.Enum`.

 

So, the statement that is not correct are:

- "It can be declared as a static nested class or inner class."