Solved

Selecting interfaces for multiple inheritance

Posted on 2004-08-20
12
222 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
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 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 35

Expert Comment

by:TimYates
ID: 11851579
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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Android development question 2 108
Problem to Alipay 10 94
program arguments vs VM arguments 4 56
Java pass by reference 3 72
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…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

737 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