使用默认方法进行接口
// 来自 NowJava.com - 时代Java interface Movable { void setX(double x); void setY(double y); double getX(); double getY(); // A default method default void move(double deltaX, double deltaY) { double newX = getX() + deltaX; double newY = getY() + deltaY; setX(newX); setY(newY); } }/**来自 时 代 Java 公 众 号 - nowjava.com**/ class Pen implements Movable { private double x; private double y; public Pen() { // By default, the pen is at (0.0, 0.0) } public Pen(double x, double y) { this.x = x; this.y = y; } public void setX(double x) { this.x = x; } public void setY(double y) { this.y = y; } public double getX() { return x; } public double getY() { return y; } public String toString() { return "Pen(" + x + ", " + y + ")"; } } public class Main { public static void main(String[] args) {