multi-inheritance design
1 posts in topic
Flat View  Flat View

Posted By:   zhebin_cong
Posted On:   Sunday, April 24, 2005 11:32 PM


in a school project,there is a "student" object that has a "score" attribute and some methods,and a "staff" object that has a "salary" attribute and special methods too,the third object is "stu_sta" which is both student and staff.it should have both "score" and "salary" attributes.

i know that java don't support multi-inheritance,it can implement multiple interfaces.but i wonder how to fulfill aforementioned scenario?

how does a child inheritant the attributes of parent INTERFACE??

Re: multi-inheritance design

Posted By:   Anonymous  
Posted On:   Monday, April 25, 2005 04:30 AM

I would use delegation:

public interface Mother {
public int doOne();
public interface Father {
public int doTwo();
public class MotherImpl implements Mother { ... }
public class FatherImpl implements Father { ... }

public class Son extends MotherImpl implements Father {

private Father _father = new FatherImpl();

// doOne() inherited

public int doTwo() {
return _father.doTwo();

For attributes use their getter/setter methods.
About | Sitemap | Contact