Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

multiple inheritance vs multiple implementation

 
Padma Kanaka
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
1)I know java does not support multiple inheritance.
Can anybody give me a precise answer for why multiple
implementation is better than multiple inheritance!

2)Accessing which variable is faster? Can you specify the order,
local variable, instance variable, static variable, index of an
array.
Thanks,
Padma
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Multiple inheritance can be done - it's there in other languages. The inventors of Java looked at those other languages and decided it brings along too much complexity for the developer and the compiler and JVM implementors. They started Java with the goal of being small and simple, not the world's ultimate OO langauge, so compromises like that make sense and we just live with them. I'm fine with the choice - single inheritance is hard enough to get right!

Any variable access on the same object or class will be fast enough to not worry about - local, static, member. I would absolutely go for human understanding in my code before any optimization of that kinda thing. Indexed arrays are probably very fast, too. The access algorithm is dead simple.

Other collections and such do have some speed differences in various operations. My Collections Crib Sheet has some hints on how to select which collection to use. BTW: I'm aware the crib sheet is missing some perfectly fine collection classes. Send me any suggestions for improvements via mail from the site. Thanks!!
[ September 25, 2004: Message edited by: Stan James ]
 
Mike Gershman
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The real killer in multiple inheritance is when methods with the same name and signature are inherited from two different parents. The rules for deciding which one to call on a child object are complicated.

Then there is diamond inheritance, where Method() in class A is inherited by two child classes B and BB, then class C inherits from B and BB. Does it matter which side Method() comes down from? Then suppose that Method() is overridden in class B but not in class BB. How is super.Method() interpreted?

The advantage of multiple implementation is that the obligation to provide a method can be inherited many times but the implementation will only be provided or inherited once. No ambiguities.
 
avaneesh reddy
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The advantage of multiple implementation is that the obligation to provide a method can be inherited many times but the implementation will only be provided or inherited once. No ambiguities.

can you make this point more clear...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic