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






2 comments:

Anonymous said...

I am developing my own barcode generating library by using a licensed barcode creating controls, and I am also stucked by the java controls to be applied. hope to get some guides.

sheela rajesh said...

Nice way of expressing your ideas with us.thanks for sharing with us and please add more information's.
JAVA Training in Chennai
JAVA Course in Chennai
Digital Marketing Course in Chennai
Python Training in Chennai
Big data training in chennai
Selenium Training in Chennai
JAVA training in Annanagar
Java courses in chennai anna nagar