Java MCQ – Enumerations
This collection of Java Multiple Choice Questions and Answers (MCQs): Quizzes & Practice Tests with Answer focuses on “Enumerations”.
1. If we add Enum constants to a TreeSet, what sort order will it use?
A Sorted by sort() method
B Sorted in the order of declaration in Enums
C Sorted alphabetically by Enums
D Sorted in descending order
2. What is the order of the variables in Enum?
A Descending order
B Ascending order
C Random order
D Depends on sort() method
3. Can we create an instance of Enum outside of Enum itself?
A True
B False
4. Which method returns the elements of the Enum class?
A getEnum()
B getEnumList()
C getEnums()
D getEnumConstants()
5. From which class do all Enums extend?
A Enums
B Enum
C EnumClass
D Object
6. Are the Enums “type-safe”?
A True
B False
7. What is the output of this program?
enum Color {
Bleu, Rouge, Vert, Blanc
};
System.out.println(Color.Bleu.ordinal());
A 0
B 1
C 2
D 3
8. What is the output of this program?
class Word
{
}
enum Enums extends Word
{
AAA, BBB, CCC, DDD;
}
A Compilation error
B Runtime error
C Exception EnumNotDefined
D It works well
9. What is the output of this program?
enum Levels
{
private machinA,
public machinB,
protected machinC;
}
A Compilation error
B Runtime error
C Exception EnumNotDefined
D It works well
10. What is the output of this program?
enum Enums
{
machinX, machinY, machinZ;
private Enums()
{
System.out.println(1);
}
}
public class ClassMain
{
public static void main(String[] args)
{
Enum en = Enums.machinY;
}
}
A Compilation error
B Runtime error
C 1
D Exception


