🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Java Enums: all 10 questions

Quiz: Java Enums · Question 1 of 10

What is the main advantage of an enum over int constants?

What is the main advantage of an enum over int constants?

  1. A.Enums use less memory than ints
  2. B.The compiler only allows the declared constants, so invalid values are caught
  3. C.Enums can be used in arithmetic
  4. D.Enums are faster to compare
Answer & explanation

Correct answer: The compiler only allows the declared constants, so invalid values are caught

A parameter of type Drink cannot receive 42, unlike an int parameter.

Can you get the rest right without peeking?

Take the timed Quiz: Java Enums quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →