1.Which keyword is used to declare an enumeration in Java?
-
A. class
-
B. interface
-
C. enum
-
D. struct
enum
enum
2.Enums in Java implicitly extend which class?
-
A. java.lang.Object
-
B. java.lang.Enum
-
C. java.lang.Comparable
-
D. No class, they are primitive types.
java.lang.Enum
java.lang.Enum
3.Can an enum have constructors in Java?
-
A. No, enums cannot have constructors.
-
B. Yes, but only public constructors.
-
C. Yes, but only private or package-private constructors.
-
D. Yes, any access modifier is allowed for enum constructors.
Yes, but only private or package-private constructors.
Yes, but only private or package-private constructors.
4.Which of the following is true about enum constants?
-
A. They are static and final by default.
-
B. They are mutable by default.
-
C. They can be instantiated multiple times.
-
D. They are treated as primitive values.
They are static and final by default.
They are static and final by default.
5.What is the purpose of the values() method in an enum?
-
A. To get the ordinal value of an enum constant.
-
B. To convert a string to an enum constant.
-
C. To return an array containing all the enum constants.
-
D. To compare two enum constants.
To return an array containing all the enum constants.
To return an array containing all the enum constants.