objects with state and behavior in oop

后端 未结 4 473
渐次进展
渐次进展 2021-02-04 05:14

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 appr

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-04 05:38

    Objects are defined by methods and fields.

    fields or state can be thought of current conditions within an object. A banana's state would be its shape and colour and size Methods or behaviours can be thought of its acting. With the banana, whether it is ripe or dry can be the behaviour.

提交回复
热议问题