Multiple choice technology programming languages

package statictest; public class TestStaticVar { static int p =100; static void setP(int p) { this.p = p; System.out.print("p== "+p); } public static void main(String[] args) { setP(500); System.out.print("p=="+p); } }

  1. p== 500 p== 100

  2. Run time exception

  3. Compiler error

  4. p== 500 p== 500

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

You cannot use 'this' inside a static method because 'this' refers to the current instance, but static methods belong to the class not to any instance. The compiler will catch this error at compile-time. The static variable 'p' should be accessed directly or via the class name, not through 'this'.