We know that abstract class contains both abstract and non - abstract methods , so what if we have only abstract methods so that we can achieve multiple inheritance like interfaces.
Here is the example:
public abstract class superclass1 {
public abstract void func ( );
}
public abstract class superclass2 {
public abstract void func ( );
}
public class test extends superclass1 , superclass2 {
/* Code goes here */
}
I know above code is not possible but why Java is not allowing it , because we define class body only after extending it just like interfaces and work correctly such that , so there will be no ambiguity and no problem.
Well, answering your question "why Java is not allowing it?": "Java doesn’t support multiple inheritances in classes because it can lead to diamond problem and rather than providing some complex way to solve it, there are better ways through which we can achieve the same result as multiple inheritances." Read more here
You say, but my class contains only abstract methods, right? But how do you guarantee that it will not change in the future? What if you have 10 purely abstract classes and inherited 100 class out of them with all the combinations and then you decide to add a non-abstract method to one of them? What if your parent class is a library class, you do not even know who and how inherited it. To avoid this complications, Java says: if you need purely abstract class and multiple inheritance, just use interfaces. In the practice I never had a big problems with this limitation. Actually, another way around, I saw examples in C++ where multiple inheritance from classes led to a very complex solutions that are very hard to maintain.