tags:

views:

83

answers:

2

As we all know "multiple inheritance" is prohibited in Java and J#. However, you can implement multiple interfaces like Runnable using Java and J#. So, how would you write your own classes to inherit from both JFC and WFC classes, and implement both JFC and WFC interfaces at the same time ? Is something like that possible......?

I know how to inherit JFC and WFC classes seperately and implement interfaces one at a time. Could someone post a sample code ? I am reading John Sharp's Microsoft Press book, and he says all that is elementary...... Can anyone help ?

+4  A: 
class FooBooImpl implements Foo, Boo {
    public void iAmFoo() {
       // do Foo#iAmFoo
    }
    public void iAmBoo() {
       // do Boo#iAmBoo
    }
}

or

class FooBooImpl extends Foo implements Boo {
    @Override
    public void iAmFoo() {
       super.iAmFoo();
       // do something
    }

    public void iAmBoo() {
       // do Boo#iAmBoo
    }
}

or (if you decided to delegate)

class SuperFooBoo {
    private Foo foo;
    private Boo boo;

    public void iAmFoo() {
       foo.iAmFoo();
    }

    public void iAmBoo() {
       boo,iAmBoo();
    }
}

Now you main limitation here would be if Foo and Boo define method of the same signature. You have to be careful mixing JFC and WFC (if they can be mixed, I don't really know) both of these are toolkits that hook into native code.

DroidIn.net
A: 

As Droidln.net said, you just create the class and say it implements the two interfaces. Then you write the methods matching those described in the interface.

If you use eclipse (and I assume most other IDEs), you can automatically create the required methods.

RodeoClown