Basic Datatypes
- What will ordinal() method provide?
enum Season {
WINTER, SPRING, SUMMER, FALL
};
System.out.println(Season.WINTER.ordinal());
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
ordinal() method provides number to the variables defined in Enum.
- What is the output of below code snippet?
enum Levels
{
private BOTTOM,
public MEDIUM,
protected TOP;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
Enum cannot have any modifiers. They are public, static and final by default.
- What is the output of below code snippet?
class Z
{
}
enum Enums extends Z
{
DCB, FEG, HIJ, LMN;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
Enum types cannot extend class.
- If we try to add Enum constants to a TreeSet, what sorting order will it use?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
Tree Set will sort the values in the order in which Enum constants are declared.
- What is the output of below code snippet?
enum Enums
{
D, E, F;
private Enums()
{
System.out.println(20);
}
}
public class MainClass
{
public static void main(String[] args)
{
Enum en = Enums.E;
}
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
The constructor of Enums is called which prints 20.