coo*_*000 -3 java inheritance interface
在.Net中,您可以使用以下代码执行此操作
Public class MyClass:ISomeInterface, SomeBaseClass
Run Code Online (Sandbox Code Playgroud)
在Java中可以做类似的事吗?
我的代码如下
public class InputHander extends OnTouchListener implements IControlHandler
Run Code Online (Sandbox Code Playgroud)
但是我收到了关于OnTouchListener的错误"没有预期接口"
是的,使用extends关键字进行类继承和implements接口实现:
public class MyClass extends SomeBaseClass implements SomeInterface
Run Code Online (Sandbox Code Playgroud)
从您的问题编辑中,您应该extends在类声明中使用类继承.换句话说,类只能从另一个类扩展,而不能从接口扩展.不允许多类继承.如果要实现接口,请implements仅使用关键字.所以,你的代码将是:
public class InputHander implements OnTouchListener, IControlHandler
Run Code Online (Sandbox Code Playgroud)
更多信息: