My Report

Java Basic Online Test – 3


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)
advertisement

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

2. Which class does all the Enums extend?

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

4. What is the order of variables in Enum?

5. What will be the output of the following Java code snippet?

 enum Levels 
{
    private TOP,
     
    public MEDIUM,
     
    protected BOTTOM;
}

6. Can we create an instance of Enum outside of Enum itself?

7. What will be the output of the following Java code snippet?

class A
{
     
}
 
enum Enums extends A
{
    ABC, BCD, CDE, DEF;
}

8. Are enums are type-safe?

9. What will be the output of the following Java code?

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

10. Which method returns the elements of Enum class?


 

Start practicing “1000 MCQs on Java”, and once you are ready, you can take tests on all topics by attempting our “Java Test Series”.

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.