21). What is the order of variables in Enum?

[A]Ascending order
[B]Descending order
[C]Random order
[D]Depends on the order() method

Show Answer

22). Can we create an instance of Enum outside of Enum itself?

[A]True
[B]False
[C]none
[D]none

Show Answer

23). Can we create an instance of Enum outside of Enum itself?

[A]True
[B]False
[C]none
[D]none

Show Answer

24). What will be the output of the following Java code?
     enum Season 
    {
        WINTER, SPRING, SUMMER, FALL
    };
    System.out.println(Season.WINTER.ordinal());

[A]0
[B]1
[C]2
[D]3

Show Answer

25). If we try to add Enum constants to a TreeSet, what sorting order will it use?
     enum Season 
    {
        WINTER, SPRING, SUMMER, FALL
    };
    System.out.println(Season.WINTER.ordinal());

[A]Sorted in the order of declaration of Enums
[B]Sorted in alphabetical order of Enums
[C]Sorted based on order() method
[D] Sorted in descending order of names of Enums

Show Answer

26). What will be the output of the following Java code snippet?
class A
{
 
}
 
enum Enums extends A
{
    ABC, BCD, CDE, DEF;
}

[A]Runtime Error
[B]Compilation Error
[C]It runs successfully
[D]EnumNotDefined Exception

Show Answer

27). What will be the output of the following Java code snippet?
 enum Levels 
{
    private TOP,
 
    public MEDIUM,
 
    protected BOTTOM;
}

[A]Runtime Error
[B]EnumNotDefined Exception
[C]It runs successfully
[D]Compilation Error

Show Answer

28). What will be the output of the following Java code snippet?
enum Enums
{
    A, B, C;
 
    private Enums()
    {
        System.out.println(10);
    }
}
 
public class MainClass
{
    public static void main(String[] args)
    {
        Enum en = Enums.B;
    }
}

[A] 10 10 10
[B]Compilation Error
[C] 10 10
[D]Runtime Exception

Show Answer

29). Which method returns the elements of Enum class?
enum Enums
{
    A, B, C;
 
    private Enums()
    {
        System.out.println(10);
    }
}
 
public class MainClass
{
    public static void main(String[] args)
    {
        Enum en = Enums.B;
    }
}

[A]getEnums()
[B]getEnumConstants()
[C]getEnumList()
[D]getEnum()

Show Answer

30). Which class does all the Enums extend?
enum Enums
{
    A, B, C;
 
    private Enums()
    {
        System.out.println(10);
    }
}
 
public class MainClass
{
    public static void main(String[] args)
    {
        Enum en = Enums.B;
    }
}

[A]Object
[B]Enums
[C]Enum
[D]EnumClass

Show Answer

31). Are enums are type-safe?
enum Enums
{
    A, B, C;
 
    private Enums()
    {
        System.out.println(10);
    }
}
 
public class MainClass
{
    public static void main(String[] args)
    {
        Enum en = Enums.B;
    }
}

[A]True
[B]False
[C]none
[D]none

Show Answer