Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #16980

Re: multiple inheritance

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!news-out.readnews.com!transit4.readnews.com!news-out.news.tds.net!newsreading01.news.tds.net!53ab2750!not-for-mail
From "Joshua Cranmer" <joshua.cranmer@1:261/38.remove-s5y-this>
Subject Re: multiple inheritance
Message-ID <501AC32C.55941.calajapr@time.synchro.net> (permalink)
X-Comment-To bob smith
Newsgroups comp.lang.java.programmer
In-Reply-To <501AC32B.55937.calajapr@time.synchro.net>
References <501AC32B.55937.calajapr@time.synchro.net>
X-FTN-AREA COMP.LANG.JAVA.PROGRAMMER
X-FTN-MSGID 1:261/38 40e1daee
X-FTN-REPLY 1:261/38 5a84727a
Content-Type text/plain; charset=IBM437
Content-Transfer-Encoding 8bit
X-Gateway time.synchro.net [Synchronet 3.16a-Win32 NewsLink 1.98]
Lines 38
Date Thu, 02 Aug 2012 19:12:00 GMT
NNTP-Posting-Host 69.21.70.65
X-Complaints-To news@tds.net
X-Trace newsreading01.news.tds.net 1343934720 69.21.70.65 (Thu, 02 Aug 2012 14:12:00 CDT)
NNTP-Posting-Date Thu, 02 Aug 2012 14:12:00 CDT
Organization tds.net
Xref csiph.com comp.lang.java.programmer:16980

Show key headers only | View raw


  To: bob smith
From: Joshua Cranmer <Pidgeot18@verizon.invalid>

On 8/1/2012 10:28 PM, bob smith wrote:
> Why doesn't Java support multiple inheritance?

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.

--
Beware of bugs in the above code; I have only proved it correct, not tried it. 
-- Donald E. Knuth

--- BBBS/Li6 v4.10 Dada-1
 * Origin: Prism bbs (1:261/38)
--- Synchronet 3.16a-Win32 NewsLink 1.98
Time Warp of the Future BBS - telnet://time.synchro.net:24

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

multiple inheritance "bob smith" <bob.smith@1:261/38.remove-s5y-this> - 2012-08-02 19:11 +0000
  Re: multiple inheritance "markspace" <markspace@1:261/38.remove-s5y-this> - 2012-08-02 19:11 +0000
    Re: multiple inheritance "Gene Wirchenko" <gene.wirchenko@1:261/38.remove-s5y-this> - 2012-08-02 19:12 +0000
  Re: multiple inheritance "Eric Sosman" <eric.sosman@1:261/38.remove-s5y-this> - 2012-08-02 19:11 +0000
  Re: multiple inheritance "Joshua Cranmer" <joshua.cranmer@1:261/38.remove-s5y-this> - 2012-08-02 19:12 +0000
    Re: multiple inheritance "Lew" <lew@1:261/38.remove-s5y-this> - 2012-08-02 19:12 +0000
    Re: multiple inheritance "Arne Vajhøj" <������
høj@1:261/38.remove-nlb-this> - 2012-08-13 18:36 +0000
  Re: multiple inheritance "Roedy Green" <roedy.green@1:261/38.remove-s5y-this> - 2012-08-02 19:12 +0000
    Re: multiple inheritance "Arne Vajhøj" <arne.vajhøj@1:261/38.remove-nlb-this> - 2012-08-13 18:36 +0000
      Re: multiple inheritance "Lew" <lew@1:261/38.remove-nlb-this> - 2012-08-13 18:36 +0000
        Re: multiple inheritance "Arne Vajhøj" <������
høj@1:261/38.remove-rj6-this> - 2012-08-18 18:36 +0000
      Re: multiple inheritance "Leif Roar Moldskred" <leif.roar.moldskred@1:261/38.remove-nlb-this> - 2012-08-13 18:36 +0000
        Re: multiple inheritance "markspace" <markspace@1:261/38.remove-nlb-this> - 2012-08-13 18:36 +0000
        Re: multiple inheritance "Arne Vajhøj" <������
høj@1:261/38.remove-rj6-this> - 2012-08-18 18:36 +0000
  Re: multiple inheritance "Jan Burse" <jan.burse@1:261/38.remove-s5y-this> - 2012-08-02 19:12 +0000

csiph-web