+ 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)
21 odpowiedzi
+ 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.
+ 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.
+ 3
Java fails at all predefined types not beeing an object, also the main function at c++ isn't member of an Object.
+ 3
What does "Java does not allow multiple inheritence" mean? Does it mean one base class can't have multiple derived ones?
+ 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
+ 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
+ 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 ☺
+ 2
Java dont have runtime polymorphism as their is no vitrual class or function in java
+ 2
friend functions and friend classes are not in Java
+ 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.
+ 1
سالم
+ 1
And additionally java doesn't supports multiple inheritance
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.
0
Yuppss
0
oop not support interface concept
0
I think abstract classes,friend classes, anonymous classes are used in java!
0
herencia múltiple
- 1
1.java does not do garbage collection
2.java does not support multiple inheritance and hybrid inheritance.
3.java does not use pointers
- 1
java doesn't support pointers
- 1
hybrid inheritance concept not support in java