Basic Datatypes


  1. What will ordinal() method provide?

    enum Season {
    WINTER, SPRING, SUMMER, FALL
    };
    System.out.println(Season.WINTER.ordinal());











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    ordinal() method provides number to the variables defined in Enum.


  1. What is the output of below code snippet?

    enum Levels
    {
    private BOTTOM,

    public MEDIUM,

    protected TOP;
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    Enum cannot have any modifiers. They are public, static and final by default.



  1. What is the output of below code snippet?

    class Z
    {

    }

    enum Enums extends Z
    {
    DCB, FEG, HIJ, LMN;
    }












  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    Enum types cannot extend class.


  1. If we try to add Enum constants to a TreeSet, what sorting order will it use?











  1. 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.



  1. 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;
    }
    }












  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    The constructor of Enums is called which prints 20.