Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!nx01.iad01.newshosting.com!newshosting.com!news-out.readnews.com!transit3.readnews.com!news-out.news.tds.net!newsreading01.news.tds.net!53ab2750!not-for-mail From: "Lew" Subject: Re: multiple inheritance Message-ID: <501D634E.56093.calajapr@time.synchro.net> X-Comment-To: Joshua Cranmer Newsgroups: comp.lang.java.programmer In-Reply-To: <501D634D.56089.calajapr@time.synchro.net> References: <501D634D.56089.calajapr@time.synchro.net> X-FTN-AREA: COMP.LANG.JAVA.PROGRAMMER X-FTN-MSGID: 1:261/38 aea458fc X-FTN-REPLY: 1:261/38 ecd1e16f Content-Type: text/plain; charset=IBM437 Content-Transfer-Encoding: 8bit X-Gateway: time.synchro.net [Synchronet 3.16a-Win32 NewsLink 1.98] Lines: 71 Date: Sat, 04 Aug 2012 18:41:35 GMT NNTP-Posting-Host: 69.21.70.65 X-Complaints-To: news@tds.net X-Trace: newsreading01.news.tds.net 1344105695 69.21.70.65 (Sat, 04 Aug 2012 13:41:35 CDT) NNTP-Posting-Date: Sat, 04 Aug 2012 13:41:35 CDT Organization: tds.net X-Received-Bytes: 3132 Xref: csiph.com comp.lang.java.programmer:17133 To: Joshua Cranmer From: "Lew" To: Joshua Cranmer From: "Lew" To: Joshua Cranmer From: Lew 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 -+- 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 -+- 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 --- 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