Multiple choice technology programming languages

class C{ int i; public static void main (String[] args) { int i; //1 private int a = 1; //2 protected int b = 1; //3 public int c = 1; //4 System.out.println(a+b+c); //5 }}

  1. Compile error at 2,3,4,5

  2. Compile error at 1,2,3,4,5

  3. prints 3

  4. none of the above

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

In Java, local variables inside methods cannot have access modifiers (private, protected, public). These modifiers only apply to class members (fields and methods). Lines 2, 3, and 4 attempt to declare local variables with access modifiers, which is a compile error. Line 5 uses these variables, adding to the errors. The class-level 'int i' is valid shadowed by the local 'int i' at line 1.