Concept of Objects
1) Concept of Objects.
Ans. An Object is an identifiable entity with certain characteristics and behaviour.
You yourself are an example of an object. Your:
Characteristics – Eyes, Ears, Nose, Hands, Legs.
Behaviour – Walk, Talk, Eat ,Sleep, Dance.
Characteristics – Name, Colour, Breed.
Behaviour – Barking, Wagging tail.
Characteristics – No of gears, No of brakes, Wheels.
Behaviour – Braking, Accelerating, Change gear.
An object has a state. It has certain characteristics and attributes like size, shape and colour. A change in these attributes are called as the objects behaviour. Each object has a unique ...view middle of the document...
• An object is an identifiable entity. Building is an object.
• Two objects cannot be same in the real world. Different in name and location.
3) Concept of Data Abstraction.
Ans. Data Abstraction refers to the act of representing essential features without including the background details or explanations.
Example: You are driving a car. You only know the essential features to drive a car. Example: gear handling, steering handling, use of clutch, accelerator, brakes, etc. But while driving do get into internal details of car like wiring, motor working, etc? You can change the gears or apply brakes. What is happening inside is hidden from you. This is abstraction where you only know the essential things to drive a car without including background details or explanations.
Example: Computer – We are using the computer but what is happening inside is hidden from you.
Example: Map of Bombay – HVB Academy will not be shown.
4) Concept of Encapsulation.
Ans. Every real world object has :
• Characteristics – variables – num1, num2.
• Behaviour – functions - add(), sub().
The wrapping up of data and functions into a single unit called a class is called Encapsulation.
• Variables/Characteristics – balance, withdraw, deposit.
• Behaviour/Methods – getBalance(), setDeposit(), setWithdraw().
To access variables we have to use methods. Variables depend on methods.
Data Abstraction – User does not know from where balance is going to come.
5) Message passing among objects.
Ans. When objects need to interact with one another, they pass/request information to one another. This interaction is known as message passing. That is objects interact with each other through messages.
Example: One department object sends message to another department object to retrieve some information. This is known as message passing.
Sometimes the object receiving the message needs more information so it knows what exactly to do. For example to send a message to change gears, you have to indicate which gear you want. This information passed along with messages are known as parameters.
Example: To change the gear of a bike to the 2nd gear, you need to send a message to the method changeGear of object bike. Also, a parameter needs to be sent that you want to change to 2nd gear. Software objects interact and communicate with each other using messages.
6) How do objects encapsulate state and behaviour?
Ans. An Object is an identifiable entity with certain characteristics, attributes and behaviour. The state of an object depends upon the values of its attributes at any given point of time.
Since state and behaviour are interwoven, they are said to be encapsulate state and behaviour. For instance, a car object has...