Professional Documents
Culture Documents
Js Lecture 06
Js Lecture 06
Js Lecture 06
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)
- 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.