Multiple choice technology programming languages

  1. enum A{A} 2. class E2{ 3. enum B{B} 4. void C(){ 5. enum D{D} 6. } 7. } which statements are true?(Choose all that apply.)

  1. Code compiles

  2. If line 1 is removed the code compiles

  3. If line 3 is removed the code compiles

  4. If line 5 is removed the code compiles

  5. If line 1,3 are removed the code compiles

  6. If line 1,3,5 are removed the code compiles

Reveal answer Fill a bubble to check yourself
D,F Correct answer
Explanation

In Java, enums can only be declared at the top level or within a class, but NOT within a method. Line 5's enum D is declared inside method C(), which is illegal and causes compilation failure. Removing line 5 (option D) fixes this. Enum A at line 1 (top-level) and enum B at line 3 (inside class E2 but outside method) are both legal. Option F works because removing all enums leaves valid code.