Is it possible to alter the values of an objects variables once it has been instantiated. If so could somebody please explain? Code example would be really helpful.
Your question, however, reveals that you do not have very much understanding of object-oriented programming. I suggest you pick up a book or find a site / online tutorial devoted to the subject. I'm not saying this to be rude, JProg, so there's no need to be upset. In particular, that comment should not be interpreted as a reflection of your abilities as a programmer in non-OOP languages. The transition is tough at first (I managed it though...)
Anyhow, to answer you question. Consider declaring your members private, and code public gettors and settors. ie:
private myBoolean = true;
public boolean getMyBoolean() { return myBoolean; }
public void setMyBoolean(boolean newVal)
{
myBoolean = newVal;
}
You don't need to have both or either for any member variable, and you can use the accesibility you wish (private, package/default, protected, public).
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.