Class
A class is a user defined blueprint or prototype from
which objects are created. It represents the set of properties or methods
that are common to all objects of one type.
Object
It is a basic
unit of Object Oriented Programming and represents the real life entities.
A typical Java program creates many objects, which as you know, interact
by invoking methods. An object consists of :
- State : It is represented by attributes of an object. It also reflects the properties of an object.
- Behavior : It is represented by methods of an object. It also reflects the response of an object with other objects.
Let us
consider an example of real world class to understand the way different characteristics
and common behaviours are embedded in its objects.
The syntax to create an object in Java:
ClassName
ObjectName = new ClassName();
How to create objects of the above mentioned class?
Object 1:
TelevisionSet objSony = new TelevisionSet();
Object 2:
TelevisionSet objLG = new TelevisionSet();
Let us take an example
to understand as how software class and objects will be used for programming
purpose.
In the structure shown above, the class ‘Rectangle’ is designed with the data members (i.e. states or attributes) – ‘length and breadth’ and member
functions –‘input(), calculate() and
display()’. The objects can be
created as shown below:
Object 1
Rectangle Area = new Rectangle();
Object 2
Rectangle Perimeter = new Rectangle();
The structure shown above, states when the objects
Area and Perimeter are created then each object will automatically possess the
data members and member function described within the class Rectangle. The allocation of data
members pertaining to each object can be different but the function to be
carried on them will be common.
Hence,
Area.input() : will accept length and breadth of
object Area
Area.calculate () : will perform calculations by using
length and breadth of object Area.
Area.display() : will display the result of calculation
of object Area.
Similarly, we can show the above tasks for the object Perimeter.
Principles of Object Oriented Programming (OOP)
1)
Data Abstraction
The
‘Data Abstraction’ is defined as an act of representing the essential features
without knowing background details.
2) Encapsulation
Wrapping
of data and functions of an object as a unit that can be used together in a
specific operation is known as ‘Encapsulation’.
3) Inheritance
Inheritance
is the process in which objects of one class can link and share some common
properties from the objects of another class.
4) Polymorphism
Polymorphism
is the process of using a function for more than one purpose. It allows the use
of different internal structures of the objects by keeping the same external
interface.
The advantages of OOP
·
Data values are
secured.
·
Mishandling of
data is protected.
·
Error detection
and correction become easier.
·
Easier in coding
complex programs.
Some
examples of OOP
Java, C++, Small Talk, Eiffel,
Python are some of the Object Oriented Programming Languages.
0 Comments:
Post a Comment