Is it possible to inherit from multiple abstract classes in Java if we make all methods of all abstract classes abstract?
Asked
Active
Viewed 569 times
-1
-
2no, there isn't; just make it an interface then; why do you need an abstract class with no method implemented – Liviu Stirb Aug 03 '18 at 06:41
3 Answers
0
Java doesn’t support Multiple Inheritance A problem occurs when there exist methods with the same signature in both the superclasses and subclass.
The Diamond Problem:
GrandParent / \ / \ Parent1 Parent2 \ / \ / Test
// A Grand parent class in diamond
class GrandParent
{
void fun()
{
System.out.println("Grandparent");
}
}
// First Parent class
class Parent1 extends GrandParent
{
void fun()
{
System.out.println("Parent1");
}
}
// Second Parent Class
class Parent2 extends GrandParent
{
void fun()
{
System.out.println("Parent2");
}
}
// Error : Test is inheriting from multiple
// classes
class Test extends Parent1, Parent2
{
public static void main(String args[])
{
Test t = new Test();
t.fun();
}
}

naveen
- 72
- 1
- 9
-
Java allows [multiple inheritance of default methods](https://www.programcreek.com/2014/12/default-methods-in-java-8-and-multiple-inheritance/) in interfaces. – Anderson Green May 14 '21 at 17:01
0
No java doesn't support multiple inheritance directly because this will leads to ambiguity while executing. This problem can be solved using interface which works similar to the multiple inheritance but the methods are defined in the subsequent classes so it does not create any ambiguity.

pradip
- 1
-1
No, Java does not support multiple inheritance. Also see Abstract classes and Multiple Inheritance.

Alexander van Oostenrijk
- 4,644
- 3
- 23
- 37
-
1Instead of posting an answer that merely refers to a duplicate question ... simply mark this one as duplicate. – Seelenvirtuose Aug 03 '18 at 07:25