• 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:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Multiple Inheritance problem persists in Interfaces

 
Ranch Hand
Posts: 66
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I tentatively made a program and found that multiple inheritance problem of C++ persists even with interfaces. Although this is definetely a special case but I want to know what is this problem known as( i know that this is perhaps known as diamond problem in C++). And is there a way out of this thing.


Output


D:\Education\Java\JavaStudyRoom\Applets>javac xyz.java
xyz.java:16: reference to i is ambiguous, both variable i in one and variable i
in two match
System.out.println(i);
^
1 error



Thanks for replying
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Disambiguation - it's the same solution as in C++ : you have to specify which of the constants you want to use:Incidentally, you'll find it a lot easier to follow code if you use the Java naming conventions - type names begin with an uppercase letter, method and variable names begin with a lowercase letter.
 
Sheriff
Posts: 22862
132
Eclipse IDE Spring TypeScript Quarkus Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the error message is clear: which i do you want? Dave's solution removes the ambiguity.
 
Suvojit Chakraborty
Ranch Hand
Posts: 66
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dave Lorde wrote:Disambiguation - it's the same solution as in C++ : you have to specify which of the constants you want to use:Incidentally, you'll find it a lot easier to follow code if you use the Java naming conventions - type names begin with an uppercase letter, method and variable names begin with a lowercase letter.




Oh i see. So we take the same old C++ approach.
But I want to ask, why do we then say that Java has overcome the diamond problem of C++ by abandoning multiple inheritance. We still can end up in such situations in Java.
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In C++ this conflict also applies to implementation. That's what Java prevents, since interfaces include the method protocols only and cannot contain method implementation.
 
He was expelled for perverse baking experiments. This tiny ad is a model student:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic