aspose file tools*
The moose likes Beginning Java and the fly likes inheritance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "inheritance" Watch "inheritance" New topic
Author

inheritance

raja ramesh
Greenhorn

Joined: Jan 09, 2008
Posts: 25
Can you please explain the word "Deadly Diamond of Death" ??
Sunny Jain
Ranch Hand

Joined: Jul 23, 2007
Posts: 433

Java doesn't support multiple inheritance because of Deadly Diamond of Death
Lets take an example:
1)take notebook and a pencil and start making a diagram

2)Suppose we have one class A, with method printMe()

3) We have two subclass B and C,Both inherits A,both Override printMe()
A

B C
connect them by arrow.

4) we have one more sublclass D, Now if Java supports multiple inheritance then we can write

class D inherits B,C

which means following :
A

B C

D

connect them by arrow again.

now suppose we have following;



Now tell me which verion of printMe() will be called , one which is defined in B or which is defined in C.
If you know the answer to this question you have understood Deadly diamond..
by the way check your paper you have already got one diamond shape diagram..!!


Thanks and Regards,
SCJP 1.5 (90%), SCWCD 1.5 (85%), The Jovial Java, java.util.concurrent tutorial
Sunny Jain
Ranch Hand

Joined: Jul 23, 2007
Posts: 433

my arrow diagram is not displaying properly here..

Let me try one again:
raja ramesh
Greenhorn

Joined: Jan 09, 2008
Posts: 25
ThanQ for early response ..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: inheritance