There are various characteristics of object oriented programming and those are -1) Abstraction, 2) Object and Classes, 3) Encapsulation, 4) Inheritance and ,5) Polymorphism.
Features of
Object Oriented Programming
There
are various characteristics of object oriented programming and those are -
1)
Abstraction
2)
Object and Classes
3) Encapsulation
4)
Inheritance and
5)
Polymorphism.
Abstraction
Definition: Abstraction means
representing only essential features by hiding all the implementation details.
In object oriented programming languages like C++, or Java class is an entity
used for data abstraction purpose.
Example
class
Student
{
int
roll;
char
name [10];
public;
void
input ();
void
display();
}
In main
function we can access the functionalities using object. For instance
Student
obj;
obj.input();
obj.display
();
Thus
only abstract representation can be presented, using class.
• Object
is an instance of a class.
• Objects
are basic run-time entities in object oriented programming.
• In C++
the class variables are called objects. Using objects we can access the member
variable and member function of a class.
• Object
represent a person, place or any item that a program handles.
• For
example - If the class is country then the objects can be India, China, Japan,
U.S.A andso on.
• A
single class can create any number of objects.
• Declaring objects -
The
syntax for declaring object is -
Class
Name Object_Name;
• Example
Fruit
f1;
For the
class Fruit the object f1 can be created.
• A
class can be defined as an entity in which data and functions are put together.
• The
concept of class is similar to the concept of structure in C.
• Syntax
of class is as given below
class
name_of_class
{
private:
variables
declarations; function declarations;
public:
variable
declarations;
function
declarations;
}; do
not forget semicolon
•Example
class
rectangle
{
private
:
int len,
br;
public:
};
void
get_data();
void
area();
void
print_data ();
• Explanation
o The
class declared in above example is rectangle.
o The
class name must be preceded by the keyword class.
o Inside
the body of the class there are two keywords used private and public. These are
called access specifiers.
• Encapsulation
is for the detailed implementation of a component which can be hidden from rest
of the system.
• In C++
the data is encapsulated.
• Definition:
Encapsulation means binding of data and method together in a single entity
called class.
• The data inside that class is accessible by the function in the same class. It is normally not accessible from the outside of the component.
Inheritance
• Definition: Inheritance is a property by
which the new classes are created using the old classes. In other words the new
classes can be developed using some of the properties of old classes.
• Inheritance support hierarchical structure.
• The old classes are referred as base classes
and the new classes are referred as derived classes. That means the derived
classes inherit the properties (data and functions) of base class.
• Example:
Here the Shape is a base class from which the Circle, Line and Rectangle are
the derived classes. These classes inherit the functionality draw() and
resize(). Similarly the Rectangle is a base class for the derived class Square.
Along with the derived properties the derived class can have its own
properties. For example the class Circle may have the function like
backgrcolor() for defining the back ground color.
Polymorphism
• Polymorphism means many structures.
• Definition: Polymorphism is the ability to
take more than one form and refers to an operation exhibiting different
behavior in different instances (situations).
• The
behavior depends on the type of data used in the operation. It plays an
important role in allowing objects with different internal structures to share
the same external interface. Without polymorphism, one has to create separate
module names for each method.
• For example the method clean is used to clean
a dish object, one that cleans a car object, and one that cleans a vegetable
object.
• With polymorphism, you create a single
"clean" method and apply it for different objects.
Object Oriented Programming: Unit I: Introduction to OOP and Java : Tag: : OOP and Java - Features of Object Oriented Programming
Object Oriented Programming
CS3391 3rd Semester CSE Dept | 2021 Regulation | 3rd Semester CSE Dept 2021 Regulation