typical misunderstanding. interface cannot do multi-inheritance. it should be called muti-subtyping.
interface does not have any implementation, what can you inherit anyway?There is a recommended replacement for multi-inheritance, but that's not interface. Use aggregation.
It's like
class C
{
   A a;
   B b;
   .....
}

解决方案 »

  1.   

    先谢过你的回复。
    我能理解你所说的意思,但我只是想问利用接口,联合等方式,
    在JAVA中怎样实现类似于C++的多重继承。
      

  2.   

    interface a {
     String tostring()
     void print()
    }
    interface b {
      String toString();
      void out
    }
    class ab implement a,b {
      String toString(){
      }
      void print(){   }
      void out(){
       //do you self
      }
    }
      

  3.   

    看来也只有用联合(aggregation)来实现所谓的“多重继承”了。
    若有高手能用其它方式实现的话,请留言给我,我另开贴放分。
    谢谢!
      

  4.   

    to CoffeeTang:
    不好意思,更新太慢,没看到你的贴,我想请教你一下:
    在class a 和class b 中的属性 num 和 bin 怎样处理?
      

  5.   

    aggregate is much better than inheritance!
    Even in C++, you should avoid inheritance and use aggregate.
      

  6.   

    public class A 
    {
    public String toString()
    {
    String Cstring = " A toString() Method";
    System.out.println(Cstring);
    return Cstring;
    }

    public void Print()
    {
    System.out.println(" A print() Method");
    }

    }public interface B
    {
    String toString(); 
    void Out();
    }public class C extends A implements B
    {
    public String toString()
    {
    String Cstring = " C toSting() Method";
    System.out.println(Cstring);
    return Cstring;
    }

    public void Out()
    {
    System.out.println(" C Out() Method");
    }

    static public void main(String argv[])
    {
    C c_Object = new C();
    c_Object.toString();
    c_Object.Out();
    c_Object.Print();
    return ;
    }
    }输出结果:C toString() Method
    C Out() Method
    A Pring() Method
      

  7.   

    class A implements IA{void a();}
    class B implements IB{void b();}
    class AB implements IA, IB
    {
        public void a(){_a.a();}
        public void b(){_b.b();}
        private IA _a;
        private IB _b;
    }
    is there anything we can't solve here?
      

  8.   

    to ajoo(jet pig):真很厉害!佩服!但不知阁下能否再稍微详细的说明一下。
    to all:不知各位高手是否还有其它的方法,请指教!
    这个贴今晚才会封贴,请大家多多参加讨论。
      

  9.   

    在Java中实现多重继承,其实我的感觉是没有实现,所以使用Interface,来了个折衷的办法,达到了多重继承的效果.
    想想看: 一个class 只能extends另一个class,但是它能implements多个interface.
      

  10.   

    wobject, my problem is that I can't see your problem. :)
    can you give an example where you think aggregation cannot solve it?
      

  11.   

    to ajoo(jet pig):请原谅我那种要把问题搞清楚的性格,我并不是不同意你的说法,用aggregation解决multi-inheritance是可行的,我只是想是否有更多的方法去解决multi-inheritance,这样可以扩充解决类似问题的思路,同时通过讨论加深对interface,aggregation,inheritance的理解
    我在此谢谢各位参加讨论,我现在就去放分(希望可以),
    我还是那句话,若有高手能用其它方式实现的话,请留言给我,我另开贴放分。
      

  12.   

    even single inheritance should be used in a disciplined way. Normally you should consider using aggregate instead of single inheritance unless you are sure aggregate does not work for you.The reason of that is quite long. If you are interested in it, we can discuss further.