I have a class A with a variable bool var = true
and a getter method getVar()
.
I m trying to create a class B that extends A and redefines var to bool var = false
. The code:
public class A{
protected boolean var = true;
public boolean getVar(){
return var;
}
}
public class B extends A{
protected boolean var = false;
}
问题是,如果我执行:
B b_class = new B();
System.out.println(b_class.getVar());
I obtain true
and I don t undestand why. What I m doing wrong?