Hello guys, I'm facing a problem I need to solve a problem of multi inherence using inner classes.
So the problem is this. I have a Father class and also a Mother class and I need that the class Son extends from both Father and Mother so Son class can respond to class to Father Interface and also Mother Interface. So I did the next code. (What I usually did). class Father{ void m(){ System.out.println("m()"); } } interface Mother{ void n(); } class Son extends Father implements Mother{ public void n(){ System.out.println("n()"); } } So we need to implement the solution using a inner class. And we did something like this. class Father{ void m(){ System.out.println("m()"); } } class Mother{ public void n(){ System.out.println("n()"); } class Son extends Father { void n(){ // Metodo wraper se llama igual e invoca a otro metodo que se llama igual. Mother.this.n(); } } public static void main(String[] args) { Mother.Son hijo = new Mother().new Son (); hijo.m(); hijo.n(); } } This approach is better according to what our teacher explain. And this solution can be use with more than two classes. And I did this. class Human{ void m(){ System.out.println("m()"); } } class Dead{ void n(){ System.out.println("n()"); } class InnerDeath extends Human{ void n(){ Dead.this.n(); } } } public class Vampire { void o(){ System.out.println("o()"); } class Dracula extends Dead.InnerDeath{ Dracula(){ new Dead().super(); } void o(){ Vampire.this.o(); } } public static void main(String[] args){ Vampire.Dracula dracula = new Vampire().new Dracula(); dracula.m(); dracula.n(); dracula.o(); } } So what I have is that, I use two inner classes one that extends from Humand and can acces to Dead attributes and methods, And It's from this class that extends Dracula and so that Dracula is the result and can respond to all calls to methods of the other classes. Is this the best approach? Do you know a better way to acomplish the expected result? I also have another posible solutions to accomplish this problem. I hope that someone can comment about it. What I want is to have a solution like a pattern to problems of what I should do if I need two class (I already have that: inherence plus inner class) three, four, five and so on. Thanks in advance. Roque Rueda. -- To post to this group, send email to javaprogrammingwithpassion@googlegroups.com To unsubscribe from this group, send email to javaprogrammingwithpassion+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/javaprogrammingwithpassion?hl=en