• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

multiple inheritance vs multiple implementation  RSS feed

 
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
 
(instanceof Sidekick)
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 ]
 
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.
 
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...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!