Why multiple inheritance is not supported in java like C++? before going to explain lets see what is multiple inheritance?
Multiple inheritance is a feature of object oriented computer programming language in which an object or class can inherit characteristics and features from more than one parent object or parent class.
See diagram below (here class C is inheriting all the features of A and B)
Above is not valid for java. e.g. multiple inheritance is not supported in java, to understand see below diagram. Here A has method m1(), B and C are getting m1() characteristic from A by single inheritance and now D is trying to get B and C characteristic e.g. m1() method. what will happen on D which m1() will be in D. This confusing case generate ambiguity. And below ambiguity problem is also called Diamond problem in multiple inheritance.
In other word we can say multiple inheritance does complicate the design and creates problem during casting, constructor chaining.
So, to avoid above issue multiple inheritance is not supported in java.
Hence we can say in other word to make simple and easy understandable and more powerful to java, It doesn't support multiple inheritance.
Thanks!!!!
Multiple inheritance is a feature of object oriented computer programming language in which an object or class can inherit characteristics and features from more than one parent object or parent class.
See diagram below (here class C is inheriting all the features of A and B)
Above is not valid for java. e.g. multiple inheritance is not supported in java, to understand see below diagram. Here A has method m1(), B and C are getting m1() characteristic from A by single inheritance and now D is trying to get B and C characteristic e.g. m1() method. what will happen on D which m1() will be in D. This confusing case generate ambiguity. And below ambiguity problem is also called Diamond problem in multiple inheritance.
In other word we can say multiple inheritance does complicate the design and creates problem during casting, constructor chaining.
So, to avoid above issue multiple inheritance is not supported in java.
Hence we can say in other word to make simple and easy understandable and more powerful to java, It doesn't support multiple inheritance.
Thanks!!!!
No comments:
Post a Comment