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;
}
The problem is that if I execute:
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?
B.getVar(), since the method isn't static. I assume you meanb_class.getVar()and fixed it.