Multiple choice technology programming languages

package inheritance; public class TestInheritance3 { protected int p = 100; } package inheritance1; import inheritance.TestInheritance3; public class TestInheritance_3 extends TestInheritance3 { void printP() { System.out.println("p= "+p); } public static void main(String[] args) { TestInheritance_3 T_3 = new TestInheritance_3(); T_3.printP(); } }

  1. p= 0

  2. p= 100

  3. Compiler Error

  4. Exception

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

The field 'p' is declared protected in the public class TestInheritance3. Subclasses in other packages inherit protected fields, so TestInheritance_3 can access 'p' directly. The program compiles successfully and prints the value 100.