Wednesday 5 February 2014

Classes and Objects

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.

So How can we differentiate objects
1. Depend on their properties
2. Depend on their behaviors

Differentiating two objects based on their properties
Lets 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 lets try to find what are the possible properties for the person object

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.
Properties 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 Java

What Is a Class?
A class is a blueprint or prototype from which objects are created.

Documentation Comments                                                 Class Declaration                                                 Home

No comments:

Post a Comment