Multiple choice technology programming languages

The Follwing code will result in a compiler error. Why? class Test { void doStuff() { private int x = 7; this.doMore(x); } }

  1. The use of This; local to a function is illegal

  2. Access modifiers can not be applied to local variables

  3. All classes must be declared public

  4. None of these

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

In Java, local variables (declared inside methods) cannot have access modifiers like private, public, protected, or static. Access modifiers can only be applied to class-level members (fields, methods, classes). The statement 'private int x = 7;' inside a method will cause a compiler error because local variables cannot be declared private.