Questions on enum data type in java and answers

Questions on enum data type in java and answers

(1)

enum Barcode{
    a,b,c,d,e;
}

public class EnumTest {
    public static void main(String[] args) {
         System.out.println(Barcode.b);
    }
}

What will output when you compile and run the above java code?

(a)1
(b)2
(c)b
(d)Compiler error






Answer:(c)

(2)

enum Barcode{
    a,b,c,d,e;
}

public class EnumTest {
    public static void main(String[] args) {
         Barcode bar=Barcode.c;
         System.out.println(bar);
    }
}

What will output when you compile and run the above java code?

(a)2
(b)3
(c)c
(d) Compiler error






Answer: (c)

(3)

enum Barcode{
     a,b,c,d,e;
}

public class EnumTest {
     public static void main(String[] args) {
          Barcode bar=Barcode.c;
          System.out.println(bar.ordinal());
    }
}

What will output when you compile and run the above java code?

(a)ab
(b)2
(c)c
(d) Compiler error






Answer: (b)

(4)

enum Barcode{
     a,b,c,d,e;
}

public class EnumTest {
     public static void main(String[] args){
         for(Barcode bar:Barcode.values())
           System.out.print(bar+"");
    }
}

What will output when you compile and run the above java code?

(a)1 2 3 4 5
(b)0 1 2 3 4
(c)a b c d e
(d)97 98 99 100 101






Answer: (c)

(5)

enum Color{
     black,white,green,yellow;
}
public class EnumTest {
     public static void main(String[] args){

          for(Color bar: Color.values())
              System.out.println(bar.ordinal());
     }
}

What will output when you compile and run the above java code?

(a)1 2 3 4 5
(b)0 1 2 3 4
(c)a b c d e
(d)97 98 99 100 101






4 comments:

Rohit Khatri said...


Business Analytics Certification Course Overview
The Professional Certification in Business Analytics is a foundation course for students and professionals who want to develop niche data skills for their chosen industry domain or function area. Become a Business Intelligence and Data Visualisation expert and surge ahead in your career. The nine-day Business Analytics certification course covers all the essential Analytical and Statistical techniques for effective business decision making. This programme introduces the student to the basic concepts of Python language. Data Science training in hyderabad

abid said...

Always so interesting to visit your site.What a great info, thank you for sharing. this will help me so much in my learning
360digitmg data science course in guwahati

Atheef said...


It has fully emerged to crown Singapore's southern shores and undoubtedly placed her on the global map of residential landmarks. I still scored the more points than I ever have in a season for GS. I think you would be hard pressed to find somebody with the same consistency I have had over the years so I am happy with that.
360DigiTMG data science course in kompally

360digitmgas said...

This is a wonderful article, Given so much info in it, These type of articles keeps the users interest in the website, and keep on sharing more ... good luck. data science training in coimbatore