Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

multiple inheritance

 
Revati Pathak
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why doesn't java allow multiple inheritance?
what are the practical dificulties in allowing
a class to extend more than 1 class.
After all , it allows multiple inheritance thro' implementation of interfaces.
 
Sean MacLean
author
Ranch Hand
Posts: 621
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't speak for the creators of Java, but since the develoment of Simula 67 there have been two schools of thought concerning object orientation and multiple inheritence. Basically, Simula 67 (often called the first oo language) promotes the concept that multiple inheritence goes against 'pure' oo principles. Languages like C++ see things differently. I'm sure lots of other folks can come up with other reasons (excuses? ).
Sean
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One of the major problems with multiple inheritance is if both parent classes have the same method. If that method is called on the child class, which method actually gets invoked?

Multiple inheritance is a very confusing concept, and doesn't have that may valid uses... the few valid uses that multiple inheritance does have can be accomplished in Java through interfaces. ( And the problem listed above isn't a problem with interfaces, since they only contain only method signatures and not actual method implementations... )

-Nate
 
Karthik Guru
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Nathan Pruett:
One of the major problems with multiple inheritance is if both parent classes have the same method. If that method is called on the child class, which method actually gets invoked?

Multiple inheritance is a very confusing concept, and doesn't have that may valid uses... the few valid uses that multiple inheritance does have can be accomplished in Java through interfaces. ( And the problem listed above isn't a problem with interfaces, since they only contain only method signatures and not actual method implementations... )

-Nate

hi Nate,
just an observation,
I noticed that C# also does'nt've multiple inheritance BUT they allow you to "optionally, explicity" :-),
define 2 different implementations for the methods with same signature coming from 2 interfaces if you happen to implement both of them. You just need to prefix the interface name in front of the methods!
I was just wondering they c'd've very well suported multiple implementation inheritance like C++ when they have given this provision.
karthik.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic