接口扩展另一个接口但实现其方法 [英] Interface extends another interface but implements its methods

查看:441
本文介绍了接口扩展另一个接口但实现其方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在java中,当一个接口扩展另一个接口时:

In java when an interface extends another interface:


  1. 为什么要实现它的方法?

  2. 当接口不能包含
    方法体时,如何实现其方法

  3. 如何在扩展其他接口
    时实现这些方法没有实现它?

  4. 实现另一个接口的接口的目的是什么?

  1. Why does it implement its methods?
  2. How can it implement its methods when an interface can't contain a method body
  3. How can it implement the methods when it extends the other interface and not implement it?
  4. What is the purpose of an interface implementing another interface?

这个有Java的主要概念!

This has major concepts in Java!

编辑:

public interface FiresDragEvents {

  void addDragHandler(DragHandler handler);

  void removeDragHandler(DragHandler handler);
}


public interface DragController extends FiresDragEvents {

  void addDragHandler(DragHandler handler);

  void removeDragHandler(DragHandler handler);

  void dragEnd();

  void dragMove();
}

在eclipse中除了实现的方法之外还有工具标志code> DragController 。

In eclipse there is the implement sign besides the implemented methods in DragController.

当我鼠标悬停它时,它说它实现了方法!!!

推荐答案


为什么要实现其方法?当接口不能包含方法体时,如何实现其方法
?如何在扩展其他接口而不实现它时实现
方法?
是实现另一个接口的接口的目的是什么?

Why does it implement its methods? How can it implement its methods when an interface can't contain method body? How can it implement the methods when it extends the other interface and not implement it? What is the purpose of an interface implementing another interface?

接口不实现另一个接口的方法但只是扩展他们。
需要接口扩展的一个例子是:考虑你有一个带有两种方法的车辆界面 moveForward moveBack 但你也需要加入飞机这是一种车辆,但有一些额外的方法,如 moveUp moveDown 所以
到底有没有:

Interface does not implement the methods of another interface but just extends them. One example where the interface extension is needed is: consider that you have a vehicle interface with two methods moveForward and moveBack but also you need to incorporate the Aircraft which is a vehicle but with some addition methods like moveUp, moveDown so in the end you have:

public interface IVehicle {
  bool moveForward(int x);
  bool moveBack(int x);
};

和飞机:

public interface IAirplane extends IVehicle {
  bool moveDown(int x);
  bool moveUp(int x);
};

这篇关于接口扩展另一个接口但实现其方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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