+ 9

What are different OOP concepts that are in C++ but not in Java?

1) C++ allows friend classes to access members of a class 2) Java all class methods are virtual. 3) Java does not allow multiple inheritance 4) Java is fully object oriented. (everything apart from basic datatypes are classes)

27th Jan 2017, 5:07 AM
Krishn Veer (CCSU)
Krishn Veer (CCSU) - avatar
22 Respuestas
+ 12
One of the main difference is that Java doesn't allow multiple inheritance, since in C++ you can do that. You can brake this theory rule in Java by "extends" one class, and "implements" multiple interfaces. Also, it can be achieved by inheritance tree, I mean extend an object which is extended by another one and so on. Java 8 breaks all the rules :) love it.
22nd Feb 2017, 10:10 PM
Ghena Ramascan
Ghena Ramascan - avatar
+ 10
All true Krishn, but I would argue that none of the ones you list are actually OOP concepts, but rather implementation details (that may or may not be OOP specific). For example friend classes in C++ (BTW you can have friend functions as well), is not required for OOP in C++. One implementation ďetail that is 'closer' to an OOP concept (although is more of an UML concept) is that composition in C++ is much easier and simpler than in Java (contrary to most things - which is much harder in C++!) . class A{} ; class B{ B(A*pa) {_pa=pa;} A*_pa; //aggregation A a2; //composition } ; A *a1 = new A; B *b = new B(&a1) ; ... delete b; /*The object_pa points to (i.e. a1) still exist at this point, but a2 doesn't i.e. the lifetime of a2 was tied to the lifetime of its container b (composition).*/ ... delete a1; Java cannot implement composition this way because everything is a reference in Java and there is no concept of 'instance' members like in C++. References/pointers are more natural for aggregation, so you have to use constructors and finalizers in Java (which are not guaranteed to run deterministically) to achieve the same effect.
28th Jan 2017, 10:41 AM
Ettienne Gilbert
Ettienne Gilbert - avatar
+ 3
Java fails at all predefined types not beeing an object, also the main function at c++ isn't member of an Object.
1st Feb 2017, 1:07 PM
Felipe Cruz
Felipe Cruz - avatar
+ 3
What does "Java does not allow multiple inheritence" mean? Does it mean one base class can't have multiple derived ones?
2nd Feb 2017, 7:37 PM
Justin Charis Chandra
Justin Charis Chandra - avatar
+ 2
the major differences are Java (not a pure OOP language itself)is closer of being a pure OOP language than C++. Java doesn't support pointers. Multiple inheritance are not there but can be achieved using Interfaces. Java doesn't has a copy constructor concept however can be achieved. Java is a platform independent language
1st Feb 2017, 3:21 PM
Nishant Amoli
Nishant Amoli - avatar
+ 2
it means that a class can only inherit from superclass. like class Cat inherits class Animal. it can't also inherit class Pet for example because it may have the same method names as animal and the compiler won't know which one to compile causing an error. there's no limit on how many classes inherit from a superclass
3rd Feb 2017, 3:32 AM
Damian Depuy
Damian Depuy - avatar
+ 2
hi Justin. No it means that one class can't have more than one parent class.So to do so we inherit only one class and as for other class we want to inherit we make that interface which makes overriding mandatory for any class that implements it. In that way we achieve multiple inheritance in Java ex class A extends B implements C here c is an interface and B is a base class Hope it helped ☺
3rd Feb 2017, 3:35 AM
Nishant Amoli
Nishant Amoli - avatar
+ 2
Java dont have runtime polymorphism as their is no vitrual class or function in java
20th Feb 2017, 2:40 PM
Mohit Sahu
Mohit Sahu - avatar
+ 2
friend functions and friend classes are not in Java
7th Mar 2017, 8:02 PM
Abhimanyu Singh
Abhimanyu Singh - avatar
+ 1
1. Wrong. Standard visibility in Java is package. So put friends in a package. 3. Basically wrong as of Java7 with default methods in interfaces. (We have Java 8 now!) 4. Which means Java is NOT objects only. Smalltalk, the first OOP language was. Scala and Kotlin are. Java and C# are not.
14th Feb 2017, 11:01 PM
1of3
1of3 - avatar
+ 1
سالم
3rd Mar 2017, 2:11 PM
salemdaiss
+ 1
And additionally java doesn't supports multiple inheritance
12th Mar 2017, 10:54 AM
yaamini rajkumar
yaamini rajkumar - avatar
0
In c++ you have multiple inheritance but you can also stimulate it with Java using special objects or interfaces. You can find some guides on the wen on how to do that but you have to stay focused while doing it as it can turn complicated and result with vulnerability in your code. You can solve it with a code security program to help you do that. I have heard of one called Checkmarx that you can try. Good luck! Ben.
5th Mar 2017, 8:00 AM
Ben hart
0
Yuppss
5th Mar 2017, 9:11 AM
Mohammad Rehan
Mohammad Rehan - avatar
0
oop not support interface concept
8th Mar 2017, 3:54 AM
Bhumiben Solanki
0
I think abstract classes,friend classes, anonymous classes are used in java!
12th Mar 2017, 10:54 AM
yaamini rajkumar
yaamini rajkumar - avatar
0
herencia múltiple
12th Mar 2017, 2:06 PM
Pablo Reyes Lorenzo
Pablo Reyes Lorenzo - avatar
- 1
1.java does not do garbage collection 2.java does not support multiple inheritance and hybrid inheritance. 3.java does not use pointers
4th Mar 2017, 7:35 PM
Sumit Lokhande
Sumit Lokhande - avatar
- 1
java doesn't support pointers
6th Mar 2017, 12:37 PM
darshan Nb
darshan Nb - avatar
- 1
hybrid inheritance concept not support in java
7th Mar 2017, 12:53 PM
Bhumiben Solanki