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






3 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

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

UK said...

The quiz information is a great way to test your knowledge of accounting concepts. The quiz covers a wide range of topics, including numeric data, text data, date data, and time data. The quiz is also very challenging, so it is a great way to prepare for exams or to brush up on your skills. Recommended is accounting assignments help UK for best services at your ease for the accounting assignments.