Java Enum Interview MCQ Questions and Answers

Study and learn Interview MCQ Questions and Answers on Java Enum or Enumeration. Attend job interviews easily with these Multiple Choice Questions. You can print these Questions in default mode to conduct exams directly. You can download these MCQs in PDF format by Choosing Print Option first and Save as PDF option next using any Web Browser.

Go through Java Theory Notes on Enum before reading these objective questions.



1) Java Enum is also called ___.
A) Enumeration
B) Numeration
C) Iteration
D) None of the above
Answer [=]
Answer[=]
2) Which is the keyword used to create an ENUM type in Java?
A) enum
B) Enum
C) enumeration
D) Enumeration
Answer [=]
Answer[=]
3) An ENUM type in Java is like a ____.
A) interface
B) class
C) abstract class
D) None of the above
Answer [=]
Answer[=]
4) An ENUM class in Java can contain ______.
A) constructors
B) methods
C) variables and constants
D) All the above
Answer [=]
Answer[=]
5) Which is true about enum constants in Java?
A) Enum constants have index.
B) The index starts with zero (0).
C) Enum constant can be accessed using a DOT (.) operator
D) All the above
Answer [=]
Answer[=]
6) Java enums are introduced in which version?
A) Java 1.4
B) Java 1.5
C) Java 6
D) Java 8
Answer [=]
Answer[=]
7) An enum variable in java can take ___ as the assigned value in Java.
A) Any integer
B) Any non null object
C) Enum constant only
D) None of the above
Answer [=]
Answer[=]


 

8) The name of an ENUM or the name of ENUM constant can be ____ in Java.
A) A string of characters that starts with an Underscore, Dollar or Alphabet
B) A string of characters that can contain numbers at any position other than zero
C) A string of characters that can be an existing keyword
D) All the above
Answer [=]
Answer[=]
9) What is the output of the below Java program with Enums?
enum Car
{
  SEDAN, HATCHBACK, SUV
}
public class EnumTest1
{
  public static void main(String[] args)
  {
    Car c1 = Car.SEDAN;
    System.out.println(c1.name() + ", " + c1);
  }
}
A) SEDAN, 0
B) SEDAN, SEDAN
C) SEDAN, 
D) None of the above
Answer [=]
Answer[=]
10) What is the output of the below Java program with Enums?
enum Bus
{
  DIESEL, ELECTRIC, HYBRID
  int mileage = 10;
}
public class EnumTest2
{
  public static void main(String[] args)
  {
    Bus bus = Bus.ELECTRIC;
    System.out.println(bus + ", " + bus.mileage);
  }
}
A) ELECTRIC, 0
B) ELECTRIC, 10
C) 1, 0
D) Compiler error
Answer [=]
Answer[=]
11) Can you define STATIC variables and STATIC methods inside an ENUM in Java?
A) Yes
B) No
C) -
D) -
Answer [=]
Answer[=]
12) An ENUM can be defined in the place ____ in Java?
A) Inside a class but outside of methods
B) Outside a class or interface
C) Inside an Interface but outside methods (abstract if any)
D) All the above
Answer [=]
Answer[=]
13) An ordinal() method of an ENUM returns _____.
A) Hash value
B) Enum constant length
C) Enum constant index which is zero based
D) None of the above
Answer [=]
Answer[=]
14) Which is the correct way of implementing ENUM constants inside SWITCH statement in Java below?
enum Marks
{
  AVERAGE, GOOD, EXCELLENT;
}
public class EnumTest3
{
  public static void main(String[] args)
  {
    Marks student2 = Marks.GOOD;

    //MISSING SWITCH STATEMENT
  }
}
A)
switch(student2)
{
case AVERAGE: System.out.println("Marks: 60"); break;
case GOOD: System.out.println("Marks: 80"); break;
case EXCELLENT: System.out.println("Marks: 90");
}
B)
switch(student2)
{
case Marks.AVERAGE: System.out.println("Marks: 60"); break;
case Marks.GOOD: System.out.println("Marks: 80"); break;
case Marks.EXCELLENT: System.out.println("Marks: 90");
}
C)
switch(student2)
{
case Marks.AVERAGE: System.out.println("Marks: 60"); break;
case GOOD: System.out.println("Marks: 80"); break;
case Marks.EXCELLENT: System.out.println("Marks: 90");
}
D)
switch(student2)
{
case Marks[0]: System.out.println("Marks: 60"); break;
case Marks[1]: System.out.println("Marks: 80"); break;
case Marks[2]: System.out.println("Marks: 90");
}
Answer [=]
Answer[=]


 

15) Can you pass values to ENUM constructors in Java?
A) No
B) Yes
C) -
D) -
Answer [=]
Answer[=]
16) What is the output of the below Java code with Enums and Constructors?
enum Ship
{
  BOAT(5), SHIP(10), VESSEL(100);
  int capacity;
  Ship(int i)
  {
    capacity = i;
  }
  Ship(){}
  void show() {System.out.println("Capacity: " + capacity);}
	
}
public class EnumTest4
{
  public static void main(String[] args)
  {
    Ship s1 = Ship.BOAT;
    s1.show();
  }
}
A) Capacity: 5
B) Capacity: 0
C) Capacity: 10
D) Capacity: 100
Answer [=]
Answer[=]
17) What is the output of the below Java code with constructors?
enum Human
{
  KID(10), BOY(30), MAN(60);
  Human(int weight)
  {
    System.out.println("Weight: " + weight);	
  }
}
public class EnumTest5
{
  public static void main(String[] args)
  {
    Human he = Human.KID;
  }
}
A)
Weight: 10
Weight: 30
Weight: 60
B)
Weight: 10
Weight: 10
Weight: 10
C)
Weight: 0
Weight: 0
Weight: 0
D) No output
Answer [=]
Answer[=]
18) Which is the correct way of looping through all ENUM constants in Java below?
enum FRUIT
{
  ORANGE, PEARS, PLUMS;
}
A)
for(FRUIT fr2: FRUIT.values())
System.out.println(fr2);
B)
//new ENUM array
FRUIT ary[] = new FRUIT[3];
ary[0] = FRUIT.ORANGE;
ary[1] = FRUIT.PEARS;
ary[2] = FRUIT.PLUMS;
for(FRUIT fr: ary)
  System.out.println(fr);
C) Both A and B
D) None of the above
Answer [=]
Answer[=]
19) An ENUM can implement an INTERFACE. State TRUE or FALSE.
A) TRUE
B) FALSE
C) -
D) -
Answer [=]
Answer[=]


Like or Share

Show some care. Like or Subscribe. [FB]...[Youtube]

C MCQ App by ExamTray 

Android APP

Java MCQ App by ExamTray 

Android APP
ALL MCQ App by ExamTray Android APP

Ad

 

Try Some Java Books

Book Price
1. Java - The Complete Reference  Check Price
2. Core Java: An Integrated Approach, Black Book Check Price
3. Java All-in-One for Dummies Check Price
4. OCP Java SE 8: Programmer II Check Price
5. Programming with Java Check Price
6. Head First Java Check Price

We may get some affiliate commission for the above purchases.