java 如何扩展两类Android活动?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7778270/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 21:25:01  来源:igfitidea点击:

how to extends two class Android activity?

javaandroid

提问by Rohit k

I want to-->

我想要-->

class mainactivity extends ListActivity,MapActivity{ }

class mainactivity 扩展了 ListActivity,MapActivity{ }

It's possible???

这是可能的???

class mainactivity extends Any java class1,Any java Class2{ }

class mainactivity extends Any java class1,Any java Class2{ }

anyone possible??

有人可能吗??

回答by A.Quiroga

you can't . java doesn't let that type of polymorphism. You must use implements for interfaces .

你不能。java 不允许这种类型的多态性。您必须为接口使用实现。

Read this

这个

回答by Android Killer

No it's not possible because you can not extend more than one class but you can implement more than one interface which is not of any use here.

不,这是不可能的,因为您不能扩展多个类,但是您可以实现多个在这里没有任何用处的接口。

回答by Jerry Abraham

Java does not support multiple inheritance, more than one class can not be extended but there is solution , but in your case i think you can use like this:

Java 不支持多重继承,不能扩展多个类但有解决方案,但在您的情况下,我认为您可以这样使用:

  class MapActivity extends Service{
   ...
  }

 class mainactivity extends ListActivity{

  MapActivity mapActivity= new MapActivity();
 }

回答by Ritesh Mehandiratta

no its not possible because in core java a class can only inherit one class . In c++ its possible to inherit more than one class. So thats why its not possible

不,这是不可能的,因为在核心 Java 中,一个类只能继承一个类。在 C++ 中,可以继承多个类。所以这就是为什么它不可能