Quote:
Originally Posted by articsky
it confuses me like object has its state and behaviour. and then you create new objects and declear some and they have attibutes and you use methods to modify them. anyone care to explain in a more easier way to understand?
|
Well, you just about hit the nail on the head there.
Objects have attributes. To change them, you need accessor functions (methods). Some attributes are public, so you can changed them directly by assigning some value to them as obj.length = 10. Some attributes are private, so you leave it up to the object to set them, by calling the appropriate accessor: obj.setLength(10). Same goes for fetching values of attributes.
As another poster said earlier, the only way to learn to write code is to write code. Also, read other people's code, and try to understand why they wrote it the way they did, down to every single statement they wrote. You can learn a lot that way. Then build upon that knowledge, try to incroporate pieces of code you've seen in other programs into your own programs.