Wednesday, December 14, 2005

Session2-Classes and Objects

Classes:
Class in Java has data and functions that operate on those data.
In writing a Class we only describe it.

Classes use the concept of abstraction and are defined as a list of abstract attributes.
By using access modifiers Data can be made inaccessible to the outside world and only those functions which are stored in

the class could be made to access them.

Objects:
They are instances of a class.
Class is the blueprint while Object is the live model built from the blueprint.
We don't create classes in memory but when we instantiate a Class then it is called an Object and it is part of memory.

Example:

A class will have a data part and a functional part

Class Person
{
//Data part
organs eyes;
organs ears;

//functional part

see()
{
//implement seeing with your eyes.
}

hear()
{
//implement hearing with your ears.
}

}

Until now this is just a blue print. When you want to make a real person you would create a real model from this blue print which is called an Object.

Person person1 = new Person();

In the above example we have combined the data part and functional part in a single

entity[Class] which is a blue print of what we want. This is encapsulation.

We can have another Class which can inherit the properties of this Person.
That is inheritance.

In next session we will look at Access Modifiers, variables and data types.

1 Comments:

Blogger வடுவூர் குமார் said...

என்னை மாதிரி ஆளுங்களுக்கு 2 தடவை படிக்கவேண்டி வரும்.
ஆர்வம் உள்ளவர்களுக்கு புரியும்.
எனக்கு புரிகிறது.:-))

1:09 AM  

Post a Comment

<< Home