Does java really support multiple inheritance ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Does java really support multiple inheritance ?

Its very well known that java does not support class based multiple inheritance but using interface that can be achieved. But main advantage of inheritance is re usability and in case of multiple inheritance based on inheritance the concrete class which will implement the child interface will have to give the implementation of all the methods defined in parents interface. So we are not able to to achieve what inheritance is there for. So does java really support multiple inheritance.

19th Feb 2017, 2:40 AM
HellBoy
HellBoy - avatar
4 Answers
+ 2
Java doesn't support multiple inheritance it only support single inheritance. You can use aggregation with Java it works like multiple inheritance.
20th Feb 2017, 6:34 AM
David Oats
David Oats - avatar
+ 1
There is no support for multiple inheritance in java. The problem with multiple inheritance is that two classes may define different ways of doing the same thing, and the subclass can't choose which one to pick. That's why Interface comes in picture. For more details please refer http://javapapers.com/core-java/why-multiple-inheritance-is-not-supported-in-java/
24th Feb 2017, 11:20 AM
Sarfaraz Alam
Sarfaraz Alam - avatar
0
@Sarafaraz: I too know all this but my question is some thing different. please read carefully and then only answer
20th Feb 2017, 5:35 PM
HellBoy
HellBoy - avatar
- 1
Using Interface we can achieve multiple inheritable. An interface can implement another interface and a class can implement as many interface as required. Here is the example. The class "Test" is implementing both interface Printable and Showable. interface Printable {   void print();   }   interface Showable {   void show();   }   class Test  implements Printable,Showable {   public void print() { System.out.println("Hello"); } public void show() { System.out.println("Welcome"); }     public static void main(String args[]) {    Test obj = new Test();   obj.print();   obj.show();    }   } Output will be: Hello Welcome
20th Feb 2017, 5:31 PM
Sarfaraz Alam
Sarfaraz Alam - avatar