objects with state and behavior in oop

Mythriel picture Mythriel · Apr 1, 2012 · Viewed 27.4k times · Source

I keep hearing the term object has behavior and state or just one of them. But what is the difference or what does it mean, and if anyone can give an example I would really appreciate it.

Answer

bong bang picture bong bang · Oct 2, 2012
  • Lamp is an object.
  • The "state" in lamp:on and off.
  • The "behavior" in lamp:turn on and turn off.

In programming you declare states in "fields" and behaviors in "methods" etc..

Read and learn object-oriented.