Object Oriented programming is a programming type that is associated with the concept of Class, Objects and various other concepts revolving around these two, like Inheritance, Polymorphism, Abstraction, Encapsulation, Overloading etc.
Give us a chance to attempt to comprehend somewhat about all these, through a basic illustration. Individuals are living structures, comprehensively classified into two kinds, Male and Female. Correct? It's actual. Each Human being(Male or Female) has two legs, two hands, two eyes, one nose, one heart and so forth. There are body parts that are basic for Male and Female, yet then there are some particular body parts, exhibit in a Male which is absent in a Female, and some body parts display in Female however not in Males.
Every single Human Being walks, eat, see, talk, hear and so forth. Presently once more, both Male and Female plays out some regular capacities, however, there are a few specifics to both, which isn't substantial for the other. For instance: A Female can conceive an offspring, while a Male can't, so this is just for the Female.
Human Anatomy is intriguing, would it say it isn't? In any case, how about we perceive how this is identified with C++ and OOPS. Here we will attempt to clarify all the OOPS ideas through this illustration and later we will have the specialized definition for this.
Object Oriented Programming Concept Definitions
Now, let us discuss some of the main features of Object Oriented Programming which you will be using in C++(technically).
1. Objects
2. Classes
3. Abstraction
4. Encapsulation
5. Inheritance
6. Overloading
7. Exception Handling
Class
Here we can take Human Being as a class. A class is a blueprint for any functional entity which defines its properties and its functions. Like Human Being, having body parts, and performing various actions.
Inheritance
Let
HumanBeing
a class, which has properties like hands, legs, eyes, ears, mouth etc and functions like walk, talk, eat, see etc. Male
and Female
are also classes, but most of the properties and functions are included in HumanBeing
, hence they can inherit everything from class HumanBeing
using the concept of Inheritance.
Objects
My name is Subham, and I am an instance or object of class
Male
. When we say, Human_Being, Male or Female, we just mean a kind, you, your friend, me we are the forms of these classes. We have a physical existence while a class is just a logical definition. We are the objects.
Abstraction
Abstraction means, showcasing only the required things to the outside world while hiding the details. Example, Human Being can talk, walk, hear, eat, but the details are hidden from the outside world. We can take our skin as the Abstraction for hiding the inside mechanism.
Encapsulation
This concept is a little tricky to explain with an example. Our Legs are bound to help us walk. Our hands, help us hold things. This binding of the properties to functions is called Encapsulation.
Polymorphism
Polymorphism is a concept, which allows us to redefine the way something works, by either changing how it is done or by changing the parts using which it is done. Both the ways have different terms for them.
If we walk using our hands, and not legs, here we will change the parts used to perform something. Hence this is called Overloading.
And if there is a defined way of walking, but I wish to walk differently, but using my legs, like everyone else. Then I can walk like I want, this will be called as Overriding.
Exception Handling
Exception handling is a feature of OOP, to handle unresolved exceptions or errors produced at runtime.
Syntax for class
class class_name
{
private:
//data members and member functions declarations
public:
//data members and member functions declarations
protected:
//data members and member functions declarations
};
|
OOPS Program in C++
class person
{
char name[20];
int id;
public:
void getdetails(){}
};
int main()
{
person p1; //p1 is a object
}
0 comments:
Post a Comment