Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

objects with state and behavior in oop

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.

like image 643
Mythriel Avatar asked Apr 01 '12 19:04

Mythriel


People also ask

What is an object What is the state and behavior of an object?

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.

Does object have state and behavior?

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).

What is something that has states and behavior called?

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.

What are Behaviours in OOP?

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.


1 Answers

  • 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.

like image 142
bong bang Avatar answered Jan 01 '23 06:01

bong bang