The main characteristics of Object oriented programming
Object oriented programming is a computer programming which is based on concept of object. A objcet-oriented defined as a data structure, software designed around data and object. Encapsulation,Abstraction, Polymorphism and inheritance are the main characteristics of object oriented programming.
Encapsulation :
Packaging an objects variables the within the protective custody of it's methods is called encapsulation.
Basic Syntax of Encapsulation:
Class Encapsulation
{
Private:
//data hidden from outside world
Int x;
Public:
//Function to set variable
//variable x
Void set (int x)
{
X= a;
}
//function to return value of
//variable x
Int get()
{
return x;
}
};
Here the blocks of Encapsulation
Abstraction:
Abstraction means hiding the details and displaying only essential information. Abstraction declare member as public in a class, private in a class. It avoids duplicate code and increases reusability.
Basic Syntax of Abstraction :
Class implementabstraction
{
Private:
Int a, b;
//method to set value of
//private member
Void set(int x, int y)
{
a = x;
b = y;
}
Void display()
{
count<<" a= " << a <<end1;
count<<" b= " << b <<end2;
}
};
Here the blocks of Abstraction
Polymorphism:
polymorphism is called to a member function will cause a different function to be executed depending on the type of object. It is a important conecpt of object oriented programming language.In a real life a man have become different characters like as a father, a husband, an employe in the same time. So the same person react different behavior in different situation. This is called polymorphism.
Basic Syntax of Polymorphism:
Class Geeks
{
public:
//function with 1 int parameter
Void func(int x)
{
count<< " value of x is " << x << end1;
}
//function with same name but 1 double parameter
Void func(double x)
{
count<< " value of x is " << x << end1;
}
//function with same name but 2 int parameters
Void func(int x, int y)
{
count<< " value of x and y is " << x << "," << y << end1;
}
};
This is a sample class, Where
we will observe Polymorphism
Int main() {
Geek obj1;
//Which function is call will depend on the peremeter passed.
//the first "func" is called
obj1.func(7);
//the second "func" is called
obj1.func(9.132);
//the third "func" is called
obj2.func(85.64);
return 0;
}
This is a driver code.
Inheritance:
The capability of a class to derive properties and
characteristics from another class is
called Inheritance.It defined as a class in terms of another class which makes easier to create another class or object.
Basic Syntax of Inheritance
//base class
class parent
{
Public:
int id_p;
};
//sub class inheriting form base class(parent)
Class child : public parent
{
Public:
int id_c;
};
This is a sample way of how we can inherit a class from an existing one.
Thanks to all read my content

