[Java] Multiple Inheritance

Hello,
I know multiple inheritance is not possible in Java...
But if I really insist, would this program be correct?

class A extends Applet implements MouseListener
{
}

class B extends A implements ActionListener
{
}

so Class B has the capability of both MouseListener and ActionListener?
I guess it is correct.... isn't it?
Thanks

implement多個interface並不被稱為Multiple Inheritance
同時extend一個base class同implement一個interface都好常見,所以係絕對無問題
interface係完全abstract的(沒有implementation),所以不會有C++出現既問題

p.s. 我都係java新手,有錯請插

[ 本帖最後由 梁炳 於 2009-8-31 19:20 編輯 ]

TOP

原帖由 梁炳 於 2009-8-31 19:19 發表
implement多個interface並不被稱為Multiple Inheritance
同時extend一個base class同implement一個interface都好常見,所以係絕對無問題
interface係完全abstract的(沒有implementation),所以不會有C++出現既問題


So abstract methods will go into Class A in my case? correct?
Thanks

[ 本帖最後由 luckiejacky 於 2009-8-31 19:21 編輯 ]

TOP

原帖由 luckiejacky 於 2009-8-31 19:20 發表


So abstract methods will go into Class A in my case? correct?
Thanks

yes, you must implement the method in the interface,
that implementation could come from a class which you extend(inherit) form

like the toString().....all interfaces can share the same toString method , no problem at all.

[ 本帖最後由 梁炳 於 2009-8-31 19:33 編輯 ]

TOP

原帖由 梁炳 於 2009-8-31 19:33 發表

yes, you must implement the method in the interface,
that implementation could come from a class which you extend(inherit) form

like the toString().....all interfaces can share the same toString met ...


謝謝 :)

TOP

原帖由 luckiejacky 於 2009-8-31 19:02 發表
Hello,
I know multiple inheritance is not possible in Java...
But if I really insist, would this program be correct?

class A extends Applet implements MouseListener
{
}

class B extends A implements  ...

You can just declare the class like below:

class A extends Applet implements MouseListener, ActionListenter {
}

TOP

原帖由 [email protected] 於 2009-8-31 22:17 發表

You can just declare the class like below:

class A extends Applet implements MouseListener, ActionListenter {
}


Thanks... once more, you're so helpful

TOP