Basic Datatypes
- 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 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.
- Can we create instance of Enum outside of Enum itself?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
Enum does not have public constructor.
- What is the order of variables in Enum?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
The compareTo() method is implemented to order the variable in ascending order.
- What is the numerical range of a char data type in Java?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
Char occupies 16-bit in memory, so it supports 2^16 i:e from 0 to 65535.