This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes Multiple Inheritance problem persists in Interfaces Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Multiple Inheritance problem persists in Interfaces" Watch "Multiple Inheritance problem persists in Interfaces" New topic
Author

Multiple Inheritance problem persists in Interfaces

Suvojit Chakraborty
Ranch Hand

Joined: Nov 10, 2009
Posts: 62
    
    1
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
Dave Lorde
Greenhorn

Joined: Apr 02, 2007
Posts: 20
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.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

I think the error message is clear: which i do you want? Dave's solution removes the ambiguity.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Suvojit Chakraborty
Ranch Hand

Joined: Nov 10, 2009
Posts: 62
    
    1
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.
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4338
    
    7

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Multiple Inheritance problem persists in Interfaces
 
Similar Threads
difference bet. abstract class and interface
Doubt in multiple inheritance
difference bet. interfaces and abstrct classes
Error in Servlet compilation
difference bet. abstract class and interface