可一个类扩展两个类?两个

2023-09-05 07:37:38 作者:冬日限定の爱恋

我的类应该扩展两个类在同一时间:

 公共类preferences延伸AbstractBillingActivity {

公共类preferences扩展preferenceActivity {
 

怎么办呢?

UPD 。由于这是不可能的,我应该怎么使用 AbstractBillingActivity 用preferences呢?

UPD2 。如果我去的接口,应创建:

BillingInterface

 公共接口BillingInterface扩展preferenceActivity,AbstractBillingActivity {

}
 

preferenceActivity

 公共接口preferenceActivity {

}
 
视频功能介绍 配置教程

AbstractBillingActivity

 公共接口AbstractBillingActivity {

        无效的onCreate(包savedInstanceState);

}
 

然后

 公共类preferences实现BillingInterface {
 

解决方案

Java不支持多重继承。

有几个解决方法我能想到的:

首先是聚集:做一个类,需要这两个活动领域

二是使用接口。

三是要重新考虑你的设计:是否有意义了 preferences 类既是 preferenceActivity 的和的的 AbstractBillingActivity

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:

BillingInterface

public interface BillingInterface extends PreferenceActivity, AbstractBillingActivity {

}

PreferenceActivity

public interface PreferenceActivity {

}

AbstractBillingActivity

public interface AbstractBillingActivity {

        void onCreate(Bundle savedInstanceState);

}

and then

public class Preferences implements BillingInterface {

解决方案

Java does not support multiple inheritance.

There are a few workarounds I can think of:

The first is aggregation: make a class that takes those two activities as fields.

The second is to use interfaces.

The third is to rethink your design: does it make sense for a Preferences class to be both a PreferenceActivity and an AbstractBillingActivity?