Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #16952
| From | Lew <lewbloch@gmail.com> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: multiple inheritance |
| Date | 2012-08-02 01:05 -0700 |
| Organization | http://groups.google.com |
| Message-ID | <7bed39a6-28cd-4edb-8425-84bd6883ea0e@googlegroups.com> (permalink) |
| References | <ad4daccd-4c15-4121-85e8-e8684c32b8a8@googlegroups.com> <jvcsu9$fvc$1@dont-email.me> |
Joshua Cranmer wrote:
> bob smith wrote:
>> Why doesn't Java support multiple inheritance?
Strictly speaking, Java does support multiple inheritance, just
not from classes.
This is because multiple inheritance of implementation is silly.
> Because multiple inheritance is really, really, really complicated and
> confusing for most users.
>
> The short answer is the diamond problem:
>
> class A { int varA; };
>
> class B : A { int varB; };
>
> class C : A { int varC; };
>
> class D : B, C { int varD; };
>
> There are two main points of contention in this kind of hierarchy:
>
> 1. How many copies of varA should D have? Intuitively, one is probably
>
> what most people would expect, but the implementations of B and C would
>
> have to cooperate in realizing that their superclass may be shared with
>
> D. It also incurs a penalty in runtime costs
>
> 2. How does initialization/override order get resolved? Is it "BFS"-y
>
> (like D, B, C, A) or "DFS"-y (D, B, A, C)? There are even more
> convoluted orders in practice (C3 appears to be the most common
> nowadays), but this is the sort of stuff that tends to cause nasty sorts
> of little edge cases in practice.
>
> It is rare in practice that you need true multiple inheritance, in the
> sense of inheritance of implementation; multiple inheritance of
> interface is common, and this is as far as Java goes.
Quite so.
--
Lew
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
multiple inheritance bob smith <bob@coolfone.comze.com> - 2012-08-01 19:28 -0700
Re: multiple inheritance markspace <-@.> - 2012-08-01 20:07 -0700
Re: multiple inheritance Gene Wirchenko <genew@ocis.net> - 2012-08-01 21:07 -0700
Re: multiple inheritance Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-08-01 23:12 -0400
Re: multiple inheritance Joshua Cranmer <Pidgeot18@verizon.invalid> - 2012-08-01 23:41 -0400
Re: multiple inheritance Lew <lewbloch@gmail.com> - 2012-08-02 01:05 -0700
Re: multiple inheritance Arne Vajhøj <arne@vajhoej.dk> - 2012-08-12 23:15 -0400
Re: multiple inheritance Roedy Green <see_website@mindprod.com.invalid> - 2012-08-02 01:10 -0700
Re: multiple inheritance Arne Vajhøj <arne@vajhoej.dk> - 2012-08-12 23:08 -0400
Re: multiple inheritance Lew <noone@lewscanon.com> - 2012-08-12 20:19 -0700
Re: multiple inheritance Arne Vajhøj <arne@vajhoej.dk> - 2012-08-17 22:33 -0400
Re: multiple inheritance Leif Roar Moldskred <leifm@dimnakorr.com> - 2012-08-13 05:55 -0500
Re: multiple inheritance markspace <-@.> - 2012-08-13 07:58 -0700
Re: multiple inheritance Arne Vajhøj <arne@vajhoej.dk> - 2012-08-17 22:38 -0400
Re: multiple inheritance Jan Burse <janburse@fastmail.fm> - 2012-08-02 10:12 +0200
csiph-web