Why Java does not multiple inheritance
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Can you please explain me that what exactly is Deadly Diamond of Death problem related to multiple inheritance due to which java does not supports Multiple Inheritance.
Thanks,
Gaurav
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Class Game has an instance variable: PlayerName
Class MyGame inherits Game (including its variable PlayerName - set this to my name).
Class YourGame also inherits Game (including its variable PlayerName - set this to your name).
Now if we were able to inherit both MyGame and YourGame together in another class called BothGames, and we wanted to access both of our names, how would we do it? There is only one variable called PlayerName.
The same could also be done with methods with the same name instead of instance variables. If both MyGame and YourGame classes override a method in the Game class and BothGames inherits both MyGame and YourGame, which method would it use?
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
They didn't allow it and came up with interfaces which is slightly more flexible.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
[ March 08, 2008: Message edited by: Nicholas Jordan ]
"The differential equations that describe dynamic interactions of power generators are similar to that of the gravitational interplay among celestial bodies, which is chaotic in nature."
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Now if we were able to inherit both MyGame and YourGame together in another class called BothGames, and we wanted to access both of our names, how would we do it? There is only one variable called PlayerName.
We can do one thing that we can make reference of particular class and access its method/instance variables, like if we want to access instance variable PlayerName, we can write.... and same for other class also.
Will this solution does not work?
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
One common trait, intrinsic or property - the are both a game. So write one class and in that class call it abstract class. Then have both myGame / yourGame extend game. Then to get my player, you do it like this:
Here, both players are GamePlayers, which have class Game as common base class, but you will notice I have made no way to give them different names. This discussion is easy to get ahead of yourself, but can be learned if you use a ladder approach to build the ideas.
[ March 08, 2008: Message edited by: Nicholas Jordan ]
"The differential equations that describe dynamic interactions of power generators are similar to that of the gravitational interplay among celestial bodies, which is chaotic in nature."
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Originally posted by Gaurav Ram:
Thanks all for replying. Like Kevin said:
We can do one thing that we can make reference of particular class and access its method/instance variables, like if we want to access instance variable PlayerName, we can write.... and same for other class also.
Will this solution does not work?
That would work because you have two references to two different objects. There is no ambiguity and no inheritance involved in doing so.
"Should array indices start at 0 or 1? My compromise of 0.5 was rejected without, I thought, proper consideration."- Stan Kelly-Bootle
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
| Bring me the box labeled "thinking cap" ... and then read this tiny ad: The new gardening playing cards kickstarter is now live! https://www.kickstarter.com/projects/paulwheaton/garden-cards |











