- 1 Why C++ is Object Oriented Programming Language.
- 2 What is class in programming language.
- 3 What is Object in Programming language.
- 4 What is inheritance in programming language.
- 5 What is encapsulation in programming language.
- 6 What is polymorphism in programming language.
- 7 Why is C++ partially Object-Oriented Programming Language?
If you land on this page intentionally or unintentionally then congratulations you are going to learn each and everything about why c++ is object oriented programming language.
C++ and other related things which are very common to other programming languages.
Let me just tell what you are going to see in this article.
- Why C++ is Object Oriented programming language
- Why C++ is partially Object Oriented Programming language
- What is object in programming language
- What is class in programming language
- What is inheritance
- What is encapsulation
- What is polymorphism
Why C++ is Object Oriented Programming Language.
Any programming language that makes use of object, classes, added to it abstraction, encapsulation and polymorphism is said to be Object Oriented Programming Language or OOPs.
C++ also makes use of these concepts, but some of the above concepts is not fully optimized by C++ therefore it is sometimes also called as partial Object Oriented Programming Language.
We will see why it is called partially object oriented but first let us understand what other terms are.
What is class in programming language.
A class is the blueprint of anything on which you want to work for example, suppose you are the head of the country and you want to tell your people that they can start manufacturing automobiles industries, then since you are the head of the country you need to declare some rules and guidelines for these automobile manufacturing industries to follow.
Now suppose your rules might be like this that car must have 4 doors, it must have 2 headlights, it must only contain only diesel engine and no petrol engines.
Now then all the car manufacturing industries in your country must have to follow these rules in order to work in your country.
Now let us assume you want to start car manufacturing industry and name it speed_on_wheels. And your friend also wants to start his won car manufacturing company and he names it Auto_engineers and so on too many people created their own industries.
Now here the head of the country will declare a class name Car and the things which we discussed that it should have 4 doors, 2 headlights, diesel engine and so. All these will come under that Car class as a method. Till this is class.
What is Object in Programming language.
As discussed earlier you wanted to create your own car manufacturing industries and you name it speed_on_wheels. So now you will create another class naming speed_on_wheels which will still follow the methods of Car class created by head of the country.
Now you start manufacturing and you named your first model SOW1.0 and I (the writer of this article) bought this car model from you and eventually million other peoples bought this same model from your company.
In this case the new class is speed_on_wheels and object SOW1.0 because it has been created from your class like wise you can have too many different models of cars and each model will be a unique object. But when I buy a car from you it became an instance for me irrespective of millions of same cars being out there in the market so when other person say harry buys same mode SOW1.0 it becomes another instance for him.
What is inheritance in programming language.
Inheritance simply means reusability of code, meaning you write one code and someone encounters a similar situation where he needs to write a same code like you so in spite of writing same code, he/she must use your code instead. Example
In above scenario the head of the country has already declared a class called Car with methods in it, now every other manufacturing company in country simply has to do is reuse his class that is extend his speed_on_wheels class so it can access Car class’s methods and functionality.
In this way the code from Car class is inherited into speed_on_wheels class.
What is encapsulation in programming language.
Now in the Car class we told that there must only have a diesel engine, now as head of country you don’t want to change this thing or don’t want anyone from outside that is car manufacturing company to change, so what you do is you protect those methods by writing certain key words based on your programming language. So now other class members cannot change the method of diesel class.
What is polymorphism in programming language.
Polymorphism means ‘same form’. This concept comes into picture when we have too many classes and all those performs same operations in some way or the other. Meaning we can have one method from a class and change it a little bit makes our own new working method example.
In above Car class we told car must have 4 doors so all other classes like speed_on_wheels inherited this method into their class and they must follow these methods but still they can alter somethings like colour of the door or thickness etc, this concept is known as polymorphism.
Why is C++ partially Object-Oriented Programming Language?
Every programming language starts execution from the main class but in C++ the main function which start initiates the execution is outside the main class.
This is java class execution.
In this the execution of code begins with main class that is hello.
But in C++ we can write and execute a fully functional code even without declaring a single class because in C++ the execution begins from main class which come by default and outside any class.
This is C++ execution.
In this the execution begins from main class and note that there is no class declared in this code even then C++ is capable of giving output.
This is the reason why C++ is also called partially object oriented programming.