method for changing a field

I don't understand why you should make a method for changing a field.

in a tutorial i found this:

void changeCadence(int newValue)

{

cadence = newValue;

}

why should you do this? cant you just write this in your code:

cadence = newValue;

instead of using the method?

i didn't understand this from c++ either.

the tutorial sais the other objects dont have to know what this object does.

but then what exactly happens in both cases?

ps. is a function in c++ the same as a method in java? and a field a variable?

[708 byte] By [omniscienta] at [2007-11-27 6:03:16]
# 1
read [url= http://forum.java.sun.com/thread.jspa?threadID=5177733&tstart=0]this thread[/url]
georgemca at 2007-7-12 16:45:48 > top of Java-index,Java Essentials,New To Java...