class A { int super_var = 1; } class B extends A { int sub_var = 2; } public class Demo{ public static void main(String []args){ A a = new
Is there a variable called sub_var in the parent class ? No. That is why you get the error -
sub_var cannot be resolved or is not a field
See this
System.out.print(a.super_var); //okay System.out.print(a.sub_var); //compile error