?
Solved

Selecting interfaces for multiple inheritance

Posted on 2004-08-20
12
Medium Priority
?
224 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 100 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
Independent Software Vendors: 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 100 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

Independent Software Vendors: 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!

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses
Course of the Month9 days, 12 hours left to enroll

762 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