Multiple choice technology programming languages

package statictest; class TestStaticSub { static int p = 100; public static void printP() { System.out.println("P in parent class..." + p); } } public class TestStaticVariable extends TestStaticSub { public static void printP() { p = 200; System.out.println("P in sub class ..." + p); } public static void main(String[] args) { TestStaticSub tsv = new TestStaticVariable(); tsv.printP(); } }

  1. P in sub class ... 200

  2. Compiler error

  3. P in parent class...100

  4. Run time exception

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

Static methods are resolved at compile‑time based on the reference type. The variable tsv is declared as TestStaticSub, so TestStaticSub.printP() is called, which prints the unchanged static field p (100). The subclass’s method is never invoked, making the stored answer correct.