Can one class extend two classes?

2020-01-29 04:04发布

My class should extend two classes at the same time:

public class Preferences extends AbstractBillingActivity {

public class Preferences extends PreferenceActivity {

How to do so?

Upd. Since this is not possible, how should I use that AbstractBillingActivity with Preferences then?

Upd2. If I go with interfaces, should I create:

  1. BillingInterface

    public interface BillingInterface extends PreferenceActivity, AbstractBillingActivity {
    
    }
    
  2. PreferenceActivity

    public interface PreferenceActivity {
    
    }
    
  3. AbstractBillingActivity

    public interface AbstractBillingActivity {
    
            void onCreate(Bundle savedInstanceState);
    
    }
    

and then

public class Preferences implements BillingInterface {

13条回答
你好瞎i
2楼-- · 2020-01-29 04:40

If you are interested in using methods from multiple classes, the best way to approach to it is to use Composition instead of Inheritence

查看更多
登录 后发表回答