[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 226
  • Last Modified:

Selecting interfaces for multiple inheritance

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
vijayam
Asked:
vijayam
  • 3
  • 2
  • 2
  • +2
2 Solutions
 
CEHJCommented:
>>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
 
girionisCommented:
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
 
vijayamAuthor Commented:
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!

 
girionisCommented:
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
 
moorthy_kulumaniCommented:
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
 
CEHJCommented:
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
 
TimYatesCommented:
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
 
CEHJCommented:
LOL
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now