package inheritance; class TestInheritance4 { String name ="TCS"; } package inheritance1; import inheritance.TestInheritance4; public class TestInheritance_4 extends TestInheritance4 { void printName() { System.out.println("name ="+name); } public static void main(String[] args) { TestInheritance_4 T_4 = new TestInheritance_4(); T_4.printName(); } }
-
Compiler Error
-
name = TCS
-
name = null
-
Exception
A
Correct answer
Explanation
The code fails to compile because the field 'name' has default (package-private) access in TestInheritance4. Default access is restricted to the same package only. Since TestInheritance_4 is in a different package (inheritance1), it cannot access 'name'. Options B and C are wrong because the code won't reach runtime. Option D is wrong because this is a compile-time access violation, not a runtime exception.