Java Objects & Classes Quiz 15
The quiz below tests your knowledge of the material learnt in Objects & Classes - Lesson 15 - Basic Enumerations.
Question 1 : What are enumerations?
- Enumerations are lists of named constants
Question 2 : How do we declare an enumerated type?
- We use the <code>enum</code> keyword.
Question 3 : Enumerations are classes?
- Enumerations ARE classes and they extend <code>java.lang.Enum</code>.
Question 4 : What are the identifiers TOMATO, CHICKEN and PRAWN in the code below known as?
enum Soup {
TOMATO, CHICKEN, PRAWN
}
- The identifiers TOMATO, CHICKEN and PRAWN are known as <i>enumeration constants</i>.
Question 5 : Does the following switch
Construct use the enum below correctly?
enum Soup {
TOMATO, CHICKEN, PRAWN
}
Soup soup = Soup.PRAWN;
switch (soup) {
case Soup.CHICKEN:
System.out.println("Our " + soup + " soup has meat in it!");
case Soup.PRAWN:
System.out.println("Our " + soup + " soup has fish in it!");
}
- The <code>case</code> statements are incorrectly qualified with the enum type <code>Soup</code> and so the <code>switch</code> statement uses the enum incorrectly.
Question 6 : What does the predefined enum method values()
return?
- The predefined enum method <code>values()</code> returns an array consisting of a list of enumeration constants.
Question 7 : How many objects are instantiated from the following enum declaration?
enum Soup {
TOMATO, CHICKEN, PRAWN
}
- An object is automatically instantiated for each <i>enumeration constant</i>, so in this case 3 objects.
Question 8 : What are enumeration constants implicitly declared as?
- All <i>enumeration constants</i> are implicitly declared as <code>public</code> and <code>static</code> members of their enum type.
Quiz Progress Bar Please select an answer
What's Next?
The next quizzes are on OO Concepts.