Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Refreshing object variables

Status
Not open for further replies.

JProg

Programmer
Apr 4, 2002
88
JP
Hi All,

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.

Thanks

DJ
 
uhm, yes, it is possible.

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).

Good luck

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top