File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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

shah rah
Ranch Hand

Joined: Jan 04, 2007
Posts: 124
I read that diamond scenario cannot be handled by "extends " clause but handled by interface. Can somebody explain this to me.


c1 -- super class

c2 and c3 extends from c1

c4 extends from c2 and c3.

Lee Kian Giap
Ranch Hand

Joined: Jan 23, 2008
Posts: 210
c1 -- super class

c2 and c3 extends from c1

c4 extends from c2 and c3.


what you have stated is a diamond case, which cannot be accomplished in java


However, can be accomplished in this way, but the following cannot be said as diamond case because it doesn't have the problem of dianmond case

Scenario 1:

interface i1 {}
interface i2 extends i1 {}
interface i3 extends i1 {}
interface i4 extends i2,i3 {}


Scenario 2:

interface i1 {}
interface i2 extends i1 {}
interface i3 extends i1 {}
class c4 implements i2,i3 {}


Scenario 3:

interface i1 {}
interface i2 extends i1 {}
class c3 implements i1 {}
class c4 extends c3 implements i2 {}


Scenario 4:

interface i1 {}
class c2 implements i1 {}
interface i3 extends i1 {}
class c4 extends c2 implements i3 {}

SCJP 6, SCWCD 5, SCBCD 5
Embla Tingeling
Ranch Hand

Joined: Oct 22, 2009
Posts: 237
Lee Kian Giap wrote:
, but the following cannot be said as diamond case because it doesn't have the problem of dianmond case


It's diamond inheritance for sure. It's just that Java avoids certain problems with diamond inheritance by not allowing implementation to be inherited from more than one source.

Note that also the Java-supported diamond inheritance of type also has its problems, for example when the same method name is inherited from different sources and clash.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: inheritance
 
Similar Threads
Reg. == for object references
Question on Reference assignment for Interface references..
how to use super
help scjp5.0 question
the algrithm in my homework