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.
State of an object - The state or attributes are the built in characteristics or properties of an object. For example, a T.V has the size, colour, model etc. Behaviour of the object - The behavior or operations of an object are its predefined functions.
Real-world objects share two characteristics: They all have state and behavior. Dogs have state (name, color, breed, hungry) and behavior (barking, fetching, wagging tail).
Software objects are modeled after real-world objects in that they too have state and behavior. A software object maintains its state in one or more variables . A variable is an item of data named by an identifier. A software object implements its behavior with methods.
Behaviors are the tasks that an object performs. A person's attributes, for example, include their age, name, and height, while their behaviors include the fact that a person can speak, run, walk, and eat. In Kotlin, attributes are called properties and behaviors are called functions.
In programming you declare states in "fields" and behaviors in "methods" etc..
Read and learn object-oriented.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With