The basic thing which are the essential feature of an object oriented programming are Inheritance, Polymorphism and Encapsulation. Any programming language that supports these feature completely are complete Object-oriented programming language whereas any language that supports all three feature but does not supports all features completely are Partial Object-oriented programming language.
Inheritance is used to provide the concept of code-reusability.
Polymorphism makes a language able to perform different task at different instance.
Encapsulation makes data abstraction (security or privacy to data) possible. In object-oriented programming language, Encapsulation is achieved with the help of a class.
Here are the reasons C++ is called partial or semi Object Oriented Language:
- Main function is outside the class : C++ supports object-oriented programming, but OO is not intrinsic to the language. You can write a valid, well-coded, excellently-styled C++ program without using an object even once.
In C++, main function is mandatory, which executes first but it resides outside the class and from there we create objects. So, here creation of class becomes optional and we can write code without using class.
While in JAVA, main function is executed first and it reside in the class which is mandatory. So, we can’t do anything without making Class. For doing the same thing as above, we need to make a class as :
- Concept of Global variable : In C++, we can declare a variable globally, which can be accessible from anywhere and hence, it does not provides complete privacy to the data as no one can be restricted to access and modify those data and so, it provides encapsulation partially whereas In JAVA, we can declare variable inside class only and we can provide access specifier to it.
// Global variable declaration:
g = 50;
// global variable g
cout << g;
// Local variable g
g = 20;
cout << g;
So, in JAVA, basically every data is asked explicitly by user if it should be accessible or not.
- Availability of Friend function: Friend Class A friend class can access private and protected members of other class in which it is declared as friend. It is sometimes useful to allow a particular class to access private members of other class.
Therefore, again the Object oriented features can be violated by C++.
Related Article: Why Java is not a purely Object-Oriented Language?
This article is contributed by Aditya Kumar. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Can a C++ class have an object of self type?
- Exception handling and object destruction | Set 1
- Object Slicing in C++
- Tips and Tricks for Competitive Programmers | Set 2 (Language to be used for Competitive Programming)
- Object Oriented Programming in C++
- Convert C/C++ code to assembly language
- Preventing Object Copy in C++ (3 Different Ways)
- Set position with seekg() in C++ language file handling
- kbhit in C language
- Where is an object stored if it is created inside a block in C++?
- Introduction to C++ Programming Language
- Vector of Vectors in C++ STL with Examples
- Array of Vectors in C++ STL
- Difference between Virtual function and Pure virtual function in C++