-1

Is it possible to inherit from multiple abstract classes in Java if we make all methods of all abstract classes abstract?

1
  • 2
    no, there isn't; just make it an interface then; why do you need an abstract class with no method implemented Commented Aug 3, 2018 at 6:41

3 Answers 3

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();
   }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Java allows multiple inheritance of default methods in interfaces.
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.

Comments

-1

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

1 Comment

Instead of posting an answer that merely refers to a duplicate question ... simply mark this one as duplicate.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.