从两班扩展 [英] Extending from two classes

查看:114
本文介绍了从两班扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能做到这一点:

How can I do this:

public class Main extends ListActivity , ControlMenu 

另外,我想知道这是这个方法是好的,我已经取得了在课堂上是ControlMenu菜单,我延伸活动的其余部分。

Also, I would like to know that is this approach is okay that I have made the menus in class which is ControlMenu and I am extending in rest of the activities.

推荐答案

您只能扩展一个类。而从许多来源实现接口。

You can only Extend a single class. And implement Interfaces from many sources.

扩展多个类不可用。唯一的解决办法我能想到的没有继承任何类,而是让每个类的内部变量,做更多的代理通过重定向请求到你的对象,你要他们去的对象。

Extending multiple classes is not available. The only solution I can think of is not inheriting either class but instead having an internal variable of each class and doing more of a proxy by redirecting the requests to your object to the object that you want them to go to.

 public class CustomActivity extends Activity {

     private AnotherClass mClass;

     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         mClass = new AnotherClass(this);
     }

     //Implement each method you want to use.
     public String getInfoFromOtherClass()
     {
        return mClass.getInfoFromOtherClass();
     }
 }

这是我想出了最好的解决方案。 您可以从两个类得到的功能,也是目前唯一实际上是一个类类型。

this is the best solution I have come up with. You can get the functionality from both classes and Still only actually be of one class type.

缺点是,你不能使用强制安装到内部类的模具。

The drawback is that you cannot fit into the Mold of the Internal class using a cast.

这篇关于从两班扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆