Object: is a bundle of data and its behaviour(often known as methods).
Objects have two characteristics: They have states and behaviors.
Examples of states and behaviors
Example 1:
Object: House
State: Address, Color, Area
Behavior: Open door, close door
So if I had to write a class based on states and behaviours of House. I can do it like this: States can be represented as instance variables and behaviours as methods of the class. We will see how to create classes in the next section of this guide.
class House { String address; String color; double are; void openDoor() { //Write code here } void closeDoor() { //Write code here } ... ... }
Example 2:
Let’s take another example.
Object: Car
State: Color, Brand, Weight, Model
Behavior: Break, Accelerate, Slow Down, Gear change.
Note: As we have seen above, the states and behaviors of an object, can be represented by variables and methods in the class respectively.