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.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Object Oriented Programming in C++
- Why is the size of an empty class not zero in C++?
- Why copy constructor argument should be const in C++?
- Why is a[i] == i[a] in C/C++ arrays?
- Why we should avoid using std::endl
- Why "using namespace std" is considered bad practice
- Why strcpy and strncpy are not safe to use?
- Why array index starts from zero ?
- Why overriding both the global new operator and the class-specific operator is not ambiguous?
- Why was C++ created?
- Why do we need reference variables if we have pointers
- Tips and Tricks for Competitive Programmers | Set 2 (Language to be used for Competitive Programming)
- Convert C/C++ code to assembly language
- Set position with seekg() in C++ language file handling
- kbhit in C language
- Introduction to C++ Programming Language
- Can a C++ class have an object of self type?
- Exception handling and object destruction | Set 1
- Object Slicing in C++
- Preventing Object Copy in C++ (3 Different Ways)