The answer for the below code is 2. Why is 5 not getting printed even though the class instantiated is 5? I do see 5 when I override the getter and setter.
public class Base {
private int count = 2;
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
}
public class Subclass extends Base {
private int count = 5;
}
public class PolyMain {
public static void main(String[] args){
Base base = new Subclass();
System.out.println(base.getCount());
}
}