• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

inheritance

 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 {}
 
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic