The moose likes Beginning Java and the fly likes inheritance Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply 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.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: inheritance
 
Similar Threads
Reg. == for object references
how to use super
the algrithm in my homework
help scjp5.0 question
Question on Reference assignment for Interface references..