Joe Lemmer wrote:Hi there,
I have made a superclass and several subclasses which extend it.
The superclass has private instance variables that I assumed the subclasses would all inherit without any issues, but when I try to compile my subclasses, I get the following error:
They are both in the same package and I assumed I was doing the right thing by making all the superclass instance variables private and have getter and setter methods which would also be inherited by the subclasses. Is this not right? Does anybody know where I am going wrong?
Many thanks
Joe
Hey Joe,
I guess private members can not be accessed by sub classes or any other classes. They are visible to same class only. Thing is like you will never share your private things with anyone even your children.
You need to follow a fix
pattern.
make class variables private
provide public getters/setters method
Hope it helps.