Solved

Selecting interfaces for multiple inheritance

Posted on 2004-08-20
12
223 Views
Last Modified: 2010-03-31
HI!

Why java has selected interface for multiple inheritance..Instead with classes.What's the reason behind selecting interfaces for multiple inheritance.In C++ it has been successfully proved multiple inheritance by useing classes.What's the problem java is facing for not using classes for multiple inheritance.

Thanks & Regards.
Vijaya.
0
Comment
Question by:vijayam
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +2
12 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 25 total points
ID: 11850833
>>In C++ it has been successfully proved multiple inheritance by useing classes

That's debatable. In fact one of the reasons often cited for not implementing multiple inheritance in Java is that it is seldom used correctly in C++ and can cause more problems than it's worth.

'Multiple inheritance' using interfaces is not really multiple inheritance at all. It's really a contract stating that the behaviours of more than one interface will be implemented.
0
 
LVL 35

Expert Comment

by:girionis
ID: 11850860
Multiple inheritance is bad and can lead to clarity and inambiguity problems. Imagine the following:

public class Child extends Father, Mother
{
   public Child()
   {
       // call parent's method
       double walking = walkPace() * 0.3;
   }
}

public class Father
{
    public int walkPace()
    {
        return 10;
    }
}

public class Mother
{
    public int walkPace()
    {
        return 8;
    }
}

In which method does the call to walkPace() in the Child class refer to? How do you distinct? This is the main reason why Java does not support multiple inheritance.
0
 

Author Comment

by:vijayam
ID: 11850914
For that ,in c++ they have virtual functions..and dynamycally they might have recognized the method .from which class this method  belongs to..

even in java also,they can implement the same procedure..why didn't they followed that one.

Vijaya.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 35

Assisted Solution

by:girionis
girionis earned 25 total points
ID: 11850925
In Java all methods are virtual by default (apart from them declared as final). But you still can't identify what method belongs to what object if they have the exact same method signature. Take a look at my exampel above and tell me how the Child class coudl identify what method to call, method walkPace from Father or from Mother?
0
 
LVL 3

Expert Comment

by:moorthy_kulumani
ID: 11851502
In java it has been deisgned such a way that when you extend u become that object type where as C++ you acquire the object properties.
moreover for the additionkl methods it acquires more characters  and properties, and when you can become a only one type of object.

Thanks and Regards

Robert

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 11851794
Yep, from the above

'In the designers' opinion, multiple inheritance causes more problems and confusion than it solves. So they cut multiple inheritance from the language (just as they cut operator overloading). The designers' extensive C++ experience taught them that multiple inheritance just wasn't worth the headache. '

, which is pretty much what i said
0
 
LVL 35

Expert Comment

by:TimYates
ID: 11851817
Yep :-)  I wasn't trying to swipe points, I was backing up what had already been said by everyone :-)

Don't accept my comment as an answer :-)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 11851843
LOL
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
The viewer will learn how to implement Singleton Design Pattern in Java.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question