How do I achieve Multiple Inheritance. Suppose I have class A and B. Both have a method called 'show' that has same type and signature in both the classes. Now I want to have a class X which has both the 'show' methods that are implemented in A and B. Thanks in Advance. Vicha
one procedure u can follow is to develop an inteface for class A or B then just implement ur class from both interfaces & provide the method defination for both methods from both interfaces.. then u can call them accordingly.. hope it would help U....
Joined: Jan 08, 2001
just define Inner Class in Interface & implement that Interface to ur class... A utility inner class will be used by all classes, which implement the interface. It would be a way of cheating on no-multi-inheritance in Java and actually made the interface fully implemented, provided the programmer is tricky enough. Interesting stuff, isn't it? I can even think of a situation in which it might be useful. i Think that would help U....
maateen: your reply is quite confusing atleast to me.... just implement ur class from both interfaces & provide the interfaces are implemented not classes.......maybe the abv sentence should read implement your interfaces from classes any comments ......... regds. - satya
Let's put it another way. You can't Each class can only have a single method with a given name and argument signature. So, you can either: a) Have two 'show' functions, with an extra argument to indicate which variant of 'show' is being invoked, and/or b) have a single incarnation of the method, and somehow try to decide what to do with it. I know neither choice is what you were after, but I believe (ie. I could be wrong here) that these sorts of situations are extremely messy to deal with, and was part of the reason the Java originators decided not to implement multiple-inheritance in the first place.
While you're on the subject, if class SomeClass extends a class with show() (for example) and implements an interface with show(), which would be called when SomeClass.show() was invoked?
Joined: Jun 03, 2000
Grant: Interesting qstn...... But praatically do you think this has any use at all! Anyways, if you implement the show() interface, you are overwriting the show() method from the parent. Hence, the show() method that you implemented is the one which is executed. On the contrary, you could do this also: - donot implement the interface explecitly. It is assumed that the interface is implemented since, the parent class implements it. I din't think this would work till I ran....was very interesting though.... chk this out.....