Solved

Selecting interfaces for multiple inheritance

Posted on 2004-08-20
12
217 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
  • 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
 
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now