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






1 comment:

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