Java 我可以同时使用工具和扩展吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38302935/
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-08-11 20:11:47  来源:igfitidea点击:

Can I use implements and extends at the same time?

javaandroid

提问by Jeyjey

Can i use the implements and the extends at the same time? Because I need to inherit something on the other class while i used implements on the same class.

我可以同时使用工具和扩展吗?因为我需要在另一个类上继承一些东西,而我在同一个类上使用了工具。

public class DetailActivity extends AppCompatActivity
implementsView.OnClickListener "extends ListActivity" 

How can it be like that?

怎么会这样?

回答by Bathsheba

Yes you can but you need to write your extendsbeforeimplements:

是的,你可以,但你需要写你extends之前implements

public class DetailActivity extends AppCompatActivity implements Interface1, Interface2

public class DetailActivity extends AppCompatActivity implements Interface1, Interface2

Any number of interfaces can be implemented, if more than one then each needs to be separated with a comma.

可以实现任意数量的接口,如果超过一个,则每个接口都需要用逗号分隔。

回答by Sohail Zahid

You can only extend one classbut you implements multiple interfacesas your need.

您只能扩展一个类,但可以根据需要实现多个接口