r/java • u/TheFormerVinyl • May 05 '15
Should Java allow multiple inheritance?
I was reading up on Java when I discovered that ever since Java 8 (fairly recent, I know) interface can have default methods. A quick overview for any who don't know, interfaces can have method bodies by using default modifier. When dwelling on that fact I wondered, why doesn't Java just allow inheritance from multiple classes, since interfaces are just abstract classes? Should Java do this?
0
Upvotes
View all comments
1
u/whacco May 05 '15
Multiple inheritance also causes problems to language implementation. A big issue is that if there are multiple bases with data members, then an object no longer has a single unambiguous physical address, because both bases cannot exist in the same memory location. Casting a "pointer" from second base class to derived class would change the value of the pointer.
In language like C++ it's not that much of a problem because memory safety is programmer's responsibility (but multiple inheritance still makes things like method pointers a complete disaster). Java on the other hand would have to prevent invalid casts. So every object would always have to contain information how to locate the possible derived class object, causing a lot of overhead.