Before,
moving in depth details of Object oriented and java features, will discuss what
an object and class is.
Objects and class in
Real World scenario
Object
An
Object is a real-world entity. For example, book, cat, box, bus, keyboard,
person, screen, cell phone etc., all are objects.
How can we
differentiate objects?
1.
Depend on their properties
2.
Depend on their behaviors
Differentiating two
objects based on their properties
Let’s
say, there are two persons A and B, we already discussed, each real-time entity
is an object. So, these two persons are objects.
First
let’s try to find what the possible properties for the person object are
Possible properties
for a person
height,
weight, color, Education Qualification, country, address are all come under
person properties.
Now
by comparing these properties we can easily differentiate two persons.
Property
|
Person A
|
Person B
|
Height
|
6ft
|
5.5ft
|
Weight
|
75Kg
|
60Kg
|
Color
|
White
|
Black
|
Country
|
India
|
America
|
As
shown in the above table, both the persons has their own properties, So we can
differentiate based on them.
Differentiating two
objects based on their behavior
Consider
the same two persons A and B. will try to figure out possible behaviors for the
person object
Possible behaviors
are
walk,
run, swim, eat, sleep, see, hear etc., Now by comparing these behaviors we can
easily differentiate two persons.
Behavior
|
Person A
|
Person B
|
walk
|
10km/hr
|
12km/hr
|
run
|
20km/hr
|
18km/hr
|
sleep
|
8
Hrs/day
|
6Hrs/day
|
Class
In
normal terms I call class as a category.
All
persons come under Human category
cat,
lion, Elephant come under Animals Category
So
a class or category is a group of objects with similar properties and
behaviors.
Objects and class in
Programming Terminology
What Is an Object?
An
object is a software bundle of related state and behavior. The main advantage
of java is you can compare objects in Java with real world objects. So it is
very easy to work with objects in C#
What Is a Class?
A
class is a blueprint or prototype from which objects are created.
No comments:
Post a Comment