I have two classes (A and B) and B extends A.
public class A {
protected int i = 1;
}
public class B extends A{
protected int i = 2;
}
In this case the program writes 1.
A a = new B();
System.out.println(a.i); //1
But if I assign value i in the constructor it writes 2.
public class B extends A{
public B(){
i=2;
}
}
A a = new B();
System.out.println(a.i); //2
Why?