Js Lecture 06

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 9

Java script

Lecture No. 6
What is an Object?
An object represents an
entity(person, thing and
concept) in the real world such
as
Something tangible (Ali, Car)
Date and Time
… What is an Object?
An object has

State (attributes, Properties, Characteristics)


Well-defined behavior (operations,
function)
Unique identity
Example – Ali is a Tangible Object
State (attributes)
Name
Age
Weight
behaviour (operations, functions)
Walks
Eats
Talk
Identity
His name
Example – Car is a Tangible Object
State (attributes)
- Color Price
- Model Engine Power
behaviour (operations)
- Accelerate - Start Car
- Change Gear Stop Car
Identity
- Its registration number
Example – Time is an Object

State (attributes)
- Hours - Seconds
- Minutes
behaviour (operations)
- Set Hours - Set Seconds
- Set Minutes
Identity
- Would have a unique ID in the model
Example – Date is an Object
State (attributes)
- Year - Day
- Month
behaviour (operations)
- Set Year - Set Day
- Set Month
Identity
- Would have a unique ID in the model
Constructor
Member function that is automatically executed
when an object of that class is created is known as
constructor
Constructor is used to initialize the objects of a
class
Constructor is used to ensure that object is in well
defined state at the time of creation
Constructor is automatically called when the object
is created
Constructor are not usually called openly
Constructor (contd.)
Constructor is a special function having same name
as the class name
Constructor does not have return type
Constructors are commonly public members
Constructor can work as normal function but
cannot return any value.

You might also like